from header_game_menus import *
from header_parties import *
from header_items import *
from header_colors import *

from module_constants import *

####################################################################################################################
#  (menu-id, menu-flags, menu_text, mesh-name, [<operations>], [<options>]),
#
#   Each game menu is a tuple that contains the following fields:
#  
#  1) Game-menu id (string): used for referencing game-menus in other files.
#     The prefix menu_ is automatically added before each game-menu-id
#
#  2) Game-menu flags (int). See header_game_menus.py for a list of available flags
#  3) Game-menu text (string).
#  4) mesh-name (string). Not currently used. Must be the string "none"
#  5) Operations block (list). A list of operations. See header_operations.py for reference.
#     The operations block is executed when the game menu is activated.
#  6) List of Menu options (List).
#     Each menu-option record is a tuple containing the following fields:
#   6.1) Menu-option-id (string) used for referencing game-menus in other files.
#        The prefix mno_ is automatically added before each menu-option.
#   6.2) Conditions block (list). This must be a valid operation block. See header_operations.py for reference. 
#        The conditions are executed for each menu option to decide whether the option will be shown to the player or not.
#   6.3) Menu-option text (string).
#   6.4) Consequences block (list). This must be a valid operation block. See header_operations.py for reference. 
#        The consequences are executed for the menu option that has been selected by the player.
#
#
# Note: The first Menu is the initial character creation menu.
####################################################################################################################

game_menus = [
#This needs to be the first window!!!
  (
    "start_game_1",0,
    "Welcome, adventurer, to Mount&Blade. Before you start the game, you must create a character. To begin, select your character's gender.",
    "none",
    [],
    [
      ("start_male",[],"Male",
       [
           (troop_set_type,0,0),
           (troop_set_slot,"trp_player",slot_player_gender,0),
           (troop_raise_attribute, "trp_player",ca_strength,1),
           (troop_raise_attribute, "trp_player",ca_charisma,1),
           (jump_to_menu,"mnu_start_game_2")
        ]
       ),
      ("start_female",[],"Female",
       [
           (troop_set_type,0,1),
           (troop_set_slot,"trp_player",slot_player_gender,1),
           (troop_raise_attribute, "trp_player",ca_agility,1),
           (troop_raise_attribute, "trp_player",ca_intelligence,1),
           (jump_to_menu,"mnu_start_game_2")
        ]
       ),
      ("go_back",[],"Go back",
       [(change_screen_quit),
        ]
       ),
      ]
  ),
#This needs to be the second window!!!
  (
    "start_phase_2",mnf_auto_enter,
    "_",
    "none",
    [],
    [
      ("let_them_go",[],"_",
       [
           (change_screen_return),
        ]
       ),
      #("tutorial_cheat",[(eq,1,0)],"CHEAT!",[(change_screen_return),
      #                               (assign, "$cheat_mode", 1),
      #                               (add_xp_to_troop, 15000, "trp_player"),
      #                               (troop_raise_skill, "trp_player", skl_leadership, 7),
      #                               (troop_raise_skill, "trp_player", skl_prisoner_management, 5),
      #                               (party_add_members, "p_main_party", "trp_swadian_knight", 10),
      ##                               (party_add_members, "p_main_party", "trp_vaegir_knight", 10),
       #                              (party_add_members, "p_main_party", "trp_vaegir_archer", 10),
      #                               (party_add_members, "p_main_party", "trp_swadian_sharpshooter", 10),
      #                               (troop_add_item, "trp_player","itm_surcoat_over_mail",0),
      #                               (troop_add_item, "trp_player","itm_byrnie",0),
      #                                   (troop_add_item, "trp_player","itm_nobleman_outfit",0),
      #                              (troop_add_item, "trp_player","itm_ragged_outfit",0),
#                                    (troop_add_item, "trp_player","itm_mail_with_surcoat",0),
#                                     (troop_add_item, "trp_player","itm_lady_dress_green",0),
       #                               (troop_add_item, "trp_player","itm_peasant_dress",0),
    #                                 (troop_add_item, "trp_player","itm_turret_hat_blue",0),
        #                             (troop_add_item, "trp_player","itm_wimple_with_veil",0), 
        #                             (troop_add_item, "trp_player","itm_wimple_a",0),
# 
  #                                   (troop_add_item, "trp_player","itm_ankle_boots",0),
 #                                   (troop_add_item, "trp_player","itm_norman_helmet",0),                                    
#                                    (troop_add_item, "trp_player","itm_torch",0),
    #                                 (troop_add_item, "trp_player","itm_sword_medieval_a",0),
    #                                 (troop_add_item, "trp_player","itm_sword_medieval_b",0),
    #                                 (troop_add_item, "trp_player","itm_sword_medieval_c",0),
    #                                 (troop_add_item, "trp_player","itm_sword_medieval_d",0),
    #                                 (troop_add_item, "trp_player","itm_sword_medieval_e",0),#

                                     #(troop_add_item, "trp_player","itm_sword_viking_a",0),
                                     #(troop_add_item, "trp_player","itm_sword_viking_b",0),
                                     #(troop_add_item, "trp_player","itm_sword_viking_c",0),


                                     #(try_for_range, ":cur_place", scenes_begin, scenes_end),
                                     #  (scene_set_slot, ":cur_place", slot_scene_visited, 1),
                                     #(try_end)]),
    ]
  ),
# This needs to be the third window!!!  
  (
    "start_game_3",0,
    "Choose scenario",
    "none",
    [],
    [
      ("go_back",[],"Go back",
       [(change_screen_quit),
        ]
       ),
    ]
  ),

# This needs to be the fourth window!!!  
  (
    "training_ground",0,
    "You approach a field where locals are training with weapons. You can practice here to improve your combat skills.",
    "none",
    [
        ],
    [
      ("go_back_dot",[],"Go back.",
       [(change_screen_quit),
        ]
       ),
    ]
  ),

# This needs to be the fifth window!!!  
  ("reports",0,
   "Which report would you like to view?",
   "none",
   [],
    [
      ("view_morale_report",[],"View party morale report.",
       [(jump_to_menu, "mnu_morale_report"),
        ]
       ),
      ("view_character_report",[],"View character report.",
       [(jump_to_menu, "mnu_character_report"),
        ]
       ),
      ("view_party_size_report",[],"View party size report.",
       [(jump_to_menu, "mnu_party_size_report"),
        ]
       ),
      ("resume_travelling",[],"Resume travelling.",
       [(change_screen_return),
        ]
       ),
      ]
  ),
  

  (
      "start_game_2",0,
      "With which faction will you be aligned?",
      "none",
      [],
      [
          ("start_hosokawa",[],"Hosokawa",
           [
               (troop_set_slot,"trp_player",slot_player_faction,'fac_hosokawa'),
               (jump_to_menu,"mnu_start_game_4")
               ]),
          ("start_yamana",[],"Yamana",
           [
               (troop_set_slot,"trp_player",slot_player_faction,'fac_yamana'),
               (jump_to_menu,"mnu_start_game_4")
               ]),
          ("start_neutral",[],"Non-aligned",
           [
               (troop_set_slot,"trp_player",slot_player_faction,2),
               (jump_to_menu,"mnu_start_game_4")
               ]),
      ("go_back_dot",[],"Go back.",[
        (jump_to_menu, "mnu_start_game_1"),
        ]),
		]
	),
(
      "start_game_4",0,
      "Before taking up a life of adventuring, you used to be...",
    "none",
    [],
    [
      ("start_bushi_male_hosokawa",[(troop_slot_eq,"trp_player",slot_player_gender,0),
                                    (troop_slot_eq,"trp_player",slot_player_faction,'fac_hosokawa'),
                                    ],"a bushi (warrior)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_bushi),
        (troop_raise_attribute, "trp_player",ca_strength,2),
        (troop_raise_attribute, "trp_player",ca_agility,2),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_skill, "trp_player",skl_weapon_master,1),
        (troop_raise_skill, "trp_player",skl_power_strike,1),
        (troop_raise_skill, "trp_player",skl_riding,2),
        (troop_raise_skill, "trp_player",skl_tactics,1),
        (troop_raise_skill, "trp_player",skl_athletics,1),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_proficiency, "trp_player",0,25),
        (troop_raise_proficiency, "trp_player",1,25),
        (troop_raise_proficiency, "trp_player",2,25),
        (troop_raise_proficiency, "trp_player",3,15),
        (troop_add_item, "trp_player","itm_haramaki_dou_a",0),
        (troop_add_item,"trp_player","itm_hitatare",0),
        (troop_add_item, "trp_player","itm_uchi_gatana",0),
        (troop_add_item, "trp_player","itm_short_su_yari",0),
        (troop_add_item, "trp_player","itm_waraji_b",0),
        (troop_add_item, "trp_player","itm_samurai_eboshi",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_trained_horse",0),
        [troop_add_gold, "trp_player", 360],
        (troop_set_slot,"trp_player",slot_player_title,"str_bushi_male"),
        (set_relation,"fac_hosokawa","fac_player_faction",3),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_ally),
        (set_relation,"fac_yamana","fac_player_faction",-3),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_enemy),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (troop_set_slot,"trp_player",slot_player_faction_points,10),
		(start_quest,'qst_class_bushi'),
		(start_quest,'qst_faction_hosokawa'),
        #(change_screen_return,0),
        (jump_to_menu,'mnu_start_game_5'),
        ]),
      ("start_bushi_female_hosokawa",[(troop_slot_eq,"trp_player",slot_player_gender,1),
                                      (troop_slot_eq,"trp_player",slot_player_faction,'fac_hosokawa'),
                                      ],"a bushi (warrior)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_bushi),
        (troop_raise_attribute, "trp_player",ca_agility,3),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_attribute, "trp_player",ca_charisma,1),
        (troop_raise_skill, "trp_player",skl_horse_archery,2),
        (troop_raise_skill, "trp_player",skl_riding,3),
        (troop_raise_skill, "trp_player",skl_first_aid,1),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_proficiency, "trp_player",0,15),
        (troop_raise_proficiency, "trp_player",1,20),
        (troop_raise_proficiency, "trp_player",2,25),
        (troop_raise_proficiency, "trp_player",3,25),
        (troop_add_item, "trp_player","itm_haramaki_dou_a",0),
        (troop_add_item, "trp_player","itm_o_haraate",0),
        (troop_add_item, "trp_player","itm_ko_naginata",0),
        (troop_add_item, "trp_player","itm_light_yumi",0),
        (troop_add_item, "trp_player","itm_kunai",0),
        (troop_add_item, "trp_player","itm_kunai",imod_heavy),
        (troop_add_item, "trp_player","itm_kunai",imod_watered_steel),
        (troop_add_item, "trp_player","itm_ya",0),
        (troop_add_item, "trp_player","itm_waraji_b",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_trained_horse",0),
        [troop_add_gold, "trp_player", 360],
		(troop_set_slot,"trp_player",slot_player_title,"str_bushi_female"),
        (set_relation,"fac_hosokawa","fac_player_faction",3),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_ally),
        (set_relation,"fac_yamana","fac_player_faction",-3),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_enemy),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (troop_set_slot,"trp_player",slot_player_faction_points,10),
        (start_quest,'qst_class_bushi'),
        (start_quest,'qst_faction_hosokawa'),
		#(change_screen_return,0),
        (jump_to_menu,'mnu_start_game_5'),
        ]),
      ("start_bushi_male_yamana",[(troop_slot_eq,"trp_player",slot_player_gender,0),
									(troop_slot_eq,"trp_player",slot_player_faction,'fac_yamana'),
                                    ],"a bushi (warrior)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_bushi),
        (troop_raise_attribute, "trp_player",ca_strength,2),
        (troop_raise_attribute, "trp_player",ca_agility,2),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_skill, "trp_player",skl_weapon_master,1),
        (troop_raise_skill, "trp_player",skl_power_strike,1),
        (troop_raise_skill, "trp_player",skl_riding,2),
        (troop_raise_skill, "trp_player",skl_tactics,1),
        (troop_raise_skill, "trp_player",skl_athletics,1),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_proficiency, "trp_player",0,25),
        (troop_raise_proficiency, "trp_player",1,25),
        (troop_raise_proficiency, "trp_player",2,25),
        (troop_raise_proficiency, "trp_player",3,15),
        (troop_add_item, "trp_player","itm_haramaki_dou_b",0),
        (troop_add_item, "trp_player","itm_uchi_gatana",0),
        (troop_add_item, "trp_player","itm_short_su_yari",0),
        (troop_add_item, "trp_player","itm_waraji_b",0),
        (troop_add_item, "trp_player","itm_samurai_eboshi",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_trained_horse",0),
        [troop_add_gold, "trp_player", 360],
        (troop_set_slot,"trp_player",slot_player_title,"str_bushi_male"),
        (set_relation,"fac_hosokawa","fac_player_faction",-3),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_enemy),
        (set_relation,"fac_yamana","fac_player_faction",3),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_ally),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (troop_set_slot,"trp_player",slot_player_faction_points,10),
        (start_quest,'qst_class_bushi'),
        (start_quest,'qst_faction_yamana'),
        (change_screen_return,0),
        ]),
      ("start_bushi_female_yamana",[(troop_slot_eq,"trp_player",slot_player_gender,1),
                                      (troop_slot_eq,"trp_player",slot_player_faction,'fac_yamana'),
                                      ],"a bushi (warrior)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_bushi),
        (troop_raise_attribute, "trp_player",ca_agility,3),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_attribute, "trp_player",ca_charisma,1),
        (troop_raise_skill, "trp_player",skl_horse_archery,2),
        (troop_raise_skill, "trp_player",skl_riding,3),
        (troop_raise_skill, "trp_player",skl_first_aid,1),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_proficiency, "trp_player",0,15),
        (troop_raise_proficiency, "trp_player",1,20),
        (troop_raise_proficiency, "trp_player",2,25),
        (troop_raise_proficiency, "trp_player",3,25),
        (troop_add_item, "trp_player","itm_haramaki_dou_b",0),
        (troop_add_item, "trp_player","itm_ko_naginata",0),
        (troop_add_item, "trp_player","itm_waraji_b",0),
        (troop_add_item, "trp_player","itm_uchi_gatana",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_trained_horse",0),
        [troop_add_gold, "trp_player", 360],
        (troop_set_slot,"trp_player",slot_player_title,"str_bushi_female"),
        (set_relation,"fac_hosokawa","fac_player_faction",-3),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_enemy),
        (set_relation,"fac_yamana","fac_player_faction",3),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_ally),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (troop_set_slot,"trp_player",slot_player_faction_points,10),
        (start_quest,'qst_class_bushi'),
        (change_screen_return,0),
        ]),
      ("start_kuge_male_hosokawa",[(troop_slot_eq,"trp_player",slot_player_gender,0),
                                      (troop_slot_eq,"trp_player",slot_player_faction,'fac_hosokawa'),
                                      ],"a kuge (noble)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_kuge),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_attribute, "trp_player",ca_charisma,3),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_skill, "trp_player",skl_riding,4),
        (troop_raise_skill, "trp_player",skl_leadership,5),
        (troop_raise_proficiency, "trp_player",0,15),
        (troop_raise_proficiency, "trp_player",1,15),
        (troop_raise_proficiency, "trp_player",2,10),
        (troop_raise_proficiency, "trp_player",3,5),
        (troop_add_item, "trp_player","itm_tachi",0),
        (troop_add_item, "trp_player","itm_tanto",0),
        (troop_add_item, "trp_player","itm_hou",0),
        (troop_add_item, "trp_player","itm_kegutsu",0),
        (troop_add_item, "trp_player","itm_bunkan_kanmuri_ita",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_riding_horse",0),
        [troop_add_gold, "trp_player", 36000],
        (party_add_members,"p_main_party","trp_samurai",2),
        (troop_set_slot,"trp_player",slot_player_title,"str_kuge_male"),
        (set_relation,"fac_hosokawa","fac_player_faction",3),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_ally),
        (set_relation,"fac_yamana","fac_player_faction",-3),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_enemy),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (troop_set_slot,"trp_player",slot_player_faction_points,20),
        (start_quest,'qst_class_kuge'),
        (start_quest,'qst_faction_hosokawa'),
        (change_screen_return,0),
        ]),
      ("start_kuge_female_hosokawa",[(troop_slot_eq,"trp_player",slot_player_gender,1),
                                      (troop_slot_eq,"trp_player",slot_player_faction,'fac_hosokawa'),
									  ],"a kuge (noble)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_kuge),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_attribute, "trp_player",ca_charisma,4),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_skill, "trp_player",skl_riding,4),
        (troop_raise_skill, "trp_player",skl_leadership,4),
        (troop_raise_proficiency, "trp_player",0,5),
        (troop_raise_proficiency, "trp_player",1,10),
        (troop_raise_proficiency, "trp_player",2,5),
        (troop_raise_proficiency, "trp_player",3,15),
        (troop_add_item, "trp_player","itm_light_yumi",0),
        (troop_add_item, "trp_player","itm_ya",0),
        (troop_add_item, "trp_player","itm_tanto",0),
        (troop_add_item, "trp_player","itm_kariginu_mo",0),
        (troop_add_item, "trp_player","itm_kegutsu",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_riding_horse",0),
        (troop_add_gold, "trp_player", 36000),
        (party_add_members,"p_main_party","trp_samurai",2),
        (troop_set_slot,"trp_player",slot_player_title,"str_kuge_female"),
        (set_relation,"fac_hosokawa","fac_player_faction",3),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_ally),
        (set_relation,"fac_yamana","fac_player_faction",-3),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_enemy),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (troop_set_slot,"trp_player",slot_player_faction_points,20),
        (start_quest,'qst_class_kuge'),
        (start_quest,'qst_faction_hosokawa'),
        (change_screen_return,0),
        ]),
      ("start_kuge_male_yamana",[(troop_slot_eq,"trp_player",slot_player_gender,0),
                                      (troop_slot_eq,"trp_player",slot_player_faction,'fac_yamana'),
									  ],"a kuge (noble)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_kuge),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_attribute, "trp_player",ca_charisma,3),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_skill, "trp_player",skl_riding,4),
        (troop_raise_skill, "trp_player",skl_leadership,5),
        (troop_raise_proficiency, "trp_player",0,15),
        (troop_raise_proficiency, "trp_player",1,15),
        (troop_raise_proficiency, "trp_player",2,10),
        (troop_raise_proficiency, "trp_player",3,5),
        (troop_add_item, "trp_player","itm_tachi",0),
        (troop_add_item, "trp_player","itm_tanto",0),
        (troop_add_item, "trp_player","itm_hou",0),
        (troop_add_item, "trp_player","itm_kegutsu",0),
        (troop_add_item, "trp_player","itm_bunkan_kanmuri_ita",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_riding_horse",0),
        [troop_add_gold, "trp_player", 36000],
        (party_add_members,"p_main_party","trp_samurai",2),
        (troop_set_slot,"trp_player",slot_player_title,"str_kuge_male"),
        (set_relation,"fac_hosokawa","fac_player_faction",-3),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_enemy),
        (set_relation,"fac_yamana","fac_player_faction",3),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_ally),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (troop_set_slot,"trp_player",slot_player_faction_points,20),
        (start_quest,'qst_class_kuge'),
        (start_quest,'qst_faction_yamana'),
        (change_screen_return,0),
        ]),
      ("start_kuge_female_yamana",[(troop_slot_eq,"trp_player",slot_player_gender,1),
                                      (troop_slot_eq,"trp_player",slot_player_faction,'fac_yamana'),
									  ],"a kuge (noble)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_kuge),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_attribute, "trp_player",ca_charisma,4),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_skill, "trp_player",skl_riding,4),
        (troop_raise_skill, "trp_player",skl_leadership,4),
        (troop_raise_proficiency, "trp_player",0,5),
        (troop_raise_proficiency, "trp_player",1,10),
        (troop_raise_proficiency, "trp_player",2,5),
        (troop_raise_proficiency, "trp_player",3,15),
        (troop_add_item, "trp_player","itm_light_yumi",0),
        (troop_add_item, "trp_player","itm_ya",0),
        (troop_add_item, "trp_player","itm_tanto",0),
        (troop_add_item, "trp_player","itm_kariginu_mo",0),
        (troop_add_item, "trp_player","itm_kegutsu",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_rice",0),
        (troop_add_item, "trp_player","itm_riding_horse",0),
        (troop_add_gold, "trp_player", 36000),
        (party_add_members,"p_main_party","trp_samurai",2),
        (troop_set_slot,"trp_player",slot_player_title,"str_kuge_female"),
        (set_relation,"fac_hosokawa","fac_player_faction",-3),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_enemy),
        (set_relation,"fac_yamana","fac_player_faction",3),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_ally),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (troop_set_slot,"trp_player",slot_player_faction_points,20),
        (start_quest,'qst_class_kuge'),
        (start_quest,'qst_faction_yamana'),
        (change_screen_return,0),
        ]),
      ("start_ronin_male",[(troop_slot_eq,"trp_player",slot_player_gender,0),
                           (troop_slot_eq,"trp_player",slot_player_faction,2),
						   ],"a ronin (masterless samurai)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_ronin),
        (troop_raise_attribute, "trp_player",ca_strength,3),
        (troop_raise_attribute, "trp_player",ca_agility,2),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_skill, "trp_player",skl_power_strike,2),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_skill, "trp_player",skl_riding,1),
        (troop_raise_skill, "trp_player",skl_spotting,1),
        (troop_raise_skill, "trp_player",skl_pathfinding,1),
        (troop_raise_skill, "trp_player",skl_tracking,1),
        (troop_raise_skill, "trp_player",skl_first_aid,1),
        (troop_raise_skill, "trp_player",skl_tactics,1),
        (troop_raise_skill, "trp_player",skl_prisoner_management,1),
        (troop_raise_proficiency, "trp_player",0,35),
        (troop_raise_proficiency, "trp_player",1,45),
        (troop_raise_proficiency, "trp_player",2,30),
        (troop_raise_proficiency, "trp_player",3,15),
        (troop_add_item,"trp_player","itm_kataginu_j",0),
        (troop_add_item,"trp_player","itm_uchi_gatana",0),
        (troop_add_item,"trp_player","itm_tanto",0),
        (troop_add_item,"trp_player","itm_waraji_b",0),
        (troop_add_item,"trp_player","itm_millet",0),
        (troop_add_item,"trp_player","itm_pack_horse",0),
        (troop_add_gold, "trp_player", 90),
        (troop_set_slot,"trp_player",slot_player_title,"str_ronin"),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_neutral),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_neutral),
        (set_relation,"fac_outlaws","fac_player_faction",-10),
        (start_quest,'qst_class_ronin'),
        (change_screen_return,0),
		# (jump_to_menu,'mnu_start_game_5'),
        ]),
      ("start_ronin_female",[(troop_slot_eq,"trp_player",slot_player_gender,1),
                           (troop_slot_eq,"trp_player",slot_player_faction,2),
						   ],"a ronin (masterless samurai)",[
        #(troop_set_slot,"trp_player",slot_player_class,class_ronin),
        (troop_raise_attribute, "trp_player",ca_strength,4),
        (troop_raise_attribute, "trp_player",ca_agility,2),
        (troop_raise_attribute, "trp_player",ca_intelligence,1),
        (troop_raise_skill, "trp_player",skl_power_strike,2),
        (troop_raise_skill, "trp_player",skl_power_draw,1),
        (troop_raise_skill, "trp_player",skl_riding,1),
        (troop_raise_skill, "trp_player",skl_spotting,1),
        (troop_raise_skill, "trp_player",skl_pathfinding,1),
        (troop_raise_skill, "trp_player",skl_tracking,1),
        (troop_raise_skill, "trp_player",skl_first_aid,1),
        (troop_raise_skill, "trp_player",skl_tactics,1),
        (troop_raise_skill, "trp_player",skl_prisoner_management,1),
        (troop_raise_proficiency, "trp_player",0,35),
        (troop_raise_proficiency, "trp_player",1,45),
        (troop_raise_proficiency, "trp_player",2,30),
        (troop_raise_proficiency, "trp_player",3,15),
        (troop_add_item,"trp_player","itm_uchiki",0),
        (troop_add_item,"trp_player","itm_uchi_gatana",0),
        (troop_add_item,"trp_player","itm_tanto",0),
        (troop_add_item,"trp_player","itm_waraji_b",0),
        (troop_add_item,"trp_player","itm_millet",0),
        [troop_add_gold, "trp_player", 90],
        (troop_set_slot,"trp_player",slot_player_title,"str_ronin"),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_neutral),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_neutral),
        (set_relation,"fac_outlaws","fac_player_faction",-10),
        (start_quest,'qst_class_ronin'),
        (change_screen_return,0),
        ]),
      ("start_merchant_male",[(troop_slot_eq,"trp_player",slot_player_gender,0),
                           (troop_slot_eq,"trp_player",slot_player_faction,2),
						   ],"a merchant",
		[
        #(troop_set_slot,"trp_player",slot_player_class,class_merchant),
        (troop_raise_attribute, "trp_player",ca_strength,1),
        (troop_raise_attribute, "trp_player",ca_intelligence,2),
        (troop_raise_attribute, "trp_player",ca_charisma,3),
        (troop_raise_skill, "trp_player",skl_spotting,1),
        (troop_raise_skill, "trp_player",skl_inventory_management,2),
        (troop_raise_skill, "trp_player",skl_trade,2),
        (troop_add_item, "trp_player","itm_kataginu_b",0),
        (troop_add_item, "trp_player","itm_waraji_b",0),
        (troop_add_item, "trp_player","itm_light_yumi",imod_bent),
        (troop_add_item, "trp_player","itm_ya",0),
        (troop_add_item, "trp_player","itm_bokken",0),
        (troop_add_item, "trp_player","itm_sushi_fish",0),
        (troop_add_item, "trp_player","itm_pack_horse",0),
        (troop_add_items, "trp_player","itm_silk",3),
        (troop_add_items, "trp_player","itm_pottery",6),
        (troop_add_items, "trp_player","itm_sake",3),
        (troop_add_gold, "trp_player", 3600),
        (troop_set_slot,"trp_player",slot_player_title,"str_merchant"),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_neutral),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_neutral),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (start_quest,'qst_class_merchant'),
        (change_screen_return,0),
        ]),
      ("start_merchant_female",[(troop_slot_eq,"trp_player",slot_player_gender,1),
                           (troop_slot_eq,"trp_player",slot_player_faction,2),
						   ],"a merchant",[
        #(troop_set_slot,"trp_player",slot_player_class,class_merchant),
        (troop_raise_attribute, "trp_player",ca_strength,1),
        (troop_raise_attribute, "trp_player",ca_intelligence,1),
        (troop_raise_attribute, "trp_player",ca_charisma,4),
        (troop_raise_skill, "trp_player",skl_spotting,1),
        (troop_raise_skill, "trp_player",skl_inventory_management,2),
        (troop_raise_skill, "trp_player",skl_trade,2),
        (troop_add_item, "trp_player","itm_kosode_f",0),
        (troop_add_item, "trp_player","itm_waraji_b",0),
        (troop_add_item, "trp_player","itm_light_yumi",imod_bent),
        (troop_add_item, "trp_player","itm_ya",0),
        (troop_add_item, "trp_player","itm_bokken",0),
        (troop_add_item, "trp_player","itm_sushi_fish",0),
        (troop_add_item, "trp_player","itm_pack_horse",0),
        (troop_add_items, "trp_player","itm_silk",3),
        (troop_add_items, "trp_player","itm_pottery",6),
        (troop_add_items, "trp_player","itm_sake",3),
        (troop_add_gold, "trp_player", 3600),
        (troop_set_slot,"trp_player",slot_player_title,"str_merchant"),
        (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_neutral),
        (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_neutral),
        (set_relation,"fac_outlaws","fac_player_faction",-15),
        (start_quest,'qst_class_merchant'),
        (change_screen_return,0),
        ]),
    ]
  ),   
(
	'start_game_5',0,
	'Do you want to get into the game, or select test mode?',
	'none',
	[],
	[
		('start_game',[],"Let's get started!",[(change_screen_return)],'none'),
		('test_mode',[],'I want to test',[(jump_to_menu,'mnu_start_game_test_modes')],'none')
		],
	),
(
	'start_game_test_modes',0,
	'Select a test mode',
	'none',
	[],
	[
		('test_mode_ashigaru',[],'Add 20 ashigaru to my party (10 yari, 10 yumi)',
			[
				(party_add_members,'p_main_party','trp_t3_spear_ashigaru_h',10),
				(party_add_members,'p_main_party','trp_t3_bow_ashigaru_h',10),
				(troop_raise_skill,'trp_player',skl_leadership,3),
				(troop_add_items,'trp_player','itm_rice',3),
				(troop_add_gold,'trp_player',10000),
				(change_screen_return),
				],
			'none'),
		('test_mode_foot_samurai',[],'Add 20 bushi to my party (10 kenshi samurai, 10 yumi samurai)',
			[
				(party_add_members,'p_main_party','trp_t2_sword_samurai_h',10),
				(party_add_members,'p_main_party','trp_t2_bow_ashigaru_h',10),
				(troop_raise_skill,'trp_player',skl_leadership,3),
				(troop_add_items,'trp_player','itm_rice',5),
				(troop_add_gold,'trp_player',15000),
				(change_screen_return),
				],
			'none'),
		('test_mode_mounted_samurai',[],'Add 20 mounted bushi to my party (10 light cavalry, 10 heavy cavalry)',
			[
				(party_add_members,'p_main_party','trp_t2_light_cav_h',10),
				(party_add_members,'p_main_party','trp_t2_heavy_cav_h',10),
				(troop_raise_skill,'trp_player',skl_leadership,3),
				(troop_add_items,'trp_player','itm_rice',3),
				(troop_add_gold,'trp_player',25000),
				(change_screen_return),
				],
			'none'),
		('test_mode_combined_arms',[],'Add 40 mixed units to my party (10 yari ashigaru, 10 yumi ashigaru, 10 foot samurai, 10 light cavalry)',
			[
				(party_add_members,'p_main_party','trp_t3_spear_ashigaru_h',10),
				(party_add_members,'p_main_party','trp_t3_bow_ashigaru_h',10),
				(party_add_members,'p_main_party','trp_t2_spear_samurai_h',10),
				(party_add_members,'p_main_party','trp_t2_light_cav_h',10),
				(troop_raise_skill,'trp_player',skl_leadership,5),
				(troop_add_items,'trp_player','itm_rice',6),
				(troop_add_gold,'trp_player',50000),
				(change_screen_return),
				],
			'none'),
			]
		),
	
  (
    "auto_return",0,
    "This menu automatically returns to caller.",
    "none",
    [(change_screen_return, 0)],
    [
    ]
  ),
  ("morale_report",0,
   "{s1}",
   "none",
   [(call_script, "script_process_player_party_morale"),
    (assign, reg1, "$g_player_party_morale_modifier_party_size"),
    (try_begin),
      (gt, reg1, 0),
      (str_store_string, s2, "@ -"),
    (else_try),
      (str_store_string, s2, "@ "),
    (try_end),

    (assign, reg2, "$g_player_party_morale_modifier_leadership"),
    (try_begin),
      (gt, reg2, 0),
      (str_store_string, s3, "@ +"),
    (else_try),
      (str_store_string, s3, "@ "),
    (try_end),

    (try_begin),
      (gt, "$g_player_party_morale_modifier_no_food", 0),
      (assign, reg7, "$g_player_party_morale_modifier_no_food"),
      (str_store_string, s5, "@^No food:  -{reg7}"),
    (else_try),
      (str_store_string, s5, "@ "),
    (try_end),
    (assign, reg3, "$g_player_party_morale_modifier_food"),
    (try_begin),
      (gt, reg3, 0),
      (str_store_string, s4, "@ +"),
    (else_try),
      (str_store_string, s4, "@ "),
    (try_end),

    (try_begin),
      (gt, "$g_player_party_morale_modifier_debt", 0),
      (assign, reg6, "$g_player_party_morale_modifier_debt"),
      (str_store_string, s6, "@^Wage debt:  -{reg6}"),
    (else_try),
      (str_store_string, s6, "@ "),
    (try_end),

    (assign, reg4, "$g_party_morale_change_due_to_battles"),
    (try_begin),
      (gt, reg4, 0),
      (str_store_string, s7, "@ +"),
    (else_try),
      (lt, reg4, 0),
      (str_store_string, s7, "@ -"),
    (else_try),
      (str_store_string, s7, "@ "),
    (try_end),
    (party_get_morale, reg5, "p_main_party"),
    (str_store_string, s1, "@Current party morale is {reg5}.^Current party morale modifiers are:^^Base morale:  +50^Party size: {s2}{reg1}^Leadership: {s3}{reg2}^Food variety: {s4}{reg3}{s5}{s6}^Recent events: {s7}{reg4}^TOTAL:  {reg5}"),
    ],
    [
      ("continue",[],"Continue...",
       [(jump_to_menu, "mnu_reports"),
        ]
       ),
      ]
  ),

  ("character_report",0,
   "{s9}",
   "none",
   [(assign, ":num_friends", 0),
    (assign, ":num_enemies", 0),
    (str_store_string, s6, "@none"),
    (str_store_string, s8, "@none"),
    (assign, reg3, "$player_honor"),
    (troop_get_slot, reg2, "trp_player", slot_troop_renown),
    (str_store_string, s9, "@Renown: {reg2}.^Honor rating: {reg3}.^Friends: {s8}.^Enemies: {s6}."),

    (call_script, "script_get_number_of_hero_centers", "trp_player"),
    (assign, ":no_centers", reg0),
    (try_begin),
      (gt, ":no_centers", 0),
      (try_for_range, ":i_center", 0, ":no_centers"),
        (call_script, "script_troop_get_leaded_center_with_index", "trp_player", ":i_center"),
        (assign, ":cur_center", reg0),
        (try_begin),
          (eq, ":i_center", 0),
          (str_store_party_name, s8, ":cur_center"),
        (else_try),
          (eq, ":i_center", 1),
          (str_store_party_name, s7, ":cur_center"),
          (str_store_string, s8, "@{s7} and {s8}"),
        (else_try),
          (str_store_party_name, s7, ":cur_center"),
          (str_store_string, s8, "@{s7}, {s8}"),
        (try_end),
      (try_end),
      (str_store_string, s9, "@Your estates are: {s8}.^{s9}"),
    (try_end),
    (try_begin),
      (gt, "$players_kingdom", 0),
      (str_store_faction_name, s8, "$players_kingdom"),
      (str_store_string, s9, "@You are a lord of {s8}.^{s9}"),
    (try_end),
    ],
    [
      ("continue",[],"Continue...",
       [(jump_to_menu, "mnu_reports"),
        ]
       ),
      ]
  ),

  ("party_size_report",0,
   "{s1}",
   "none",
   [(call_script, "script_game_get_party_companion_limit"),
    (assign, ":party_size_limit", reg0),

    (store_skill_level, ":leadership", "skl_leadership", "trp_player"),
    (val_mul, ":leadership", 3),
    (store_attribute_level, ":charisma", "trp_player", ca_charisma),

    (troop_get_slot, ":renown", "trp_player", slot_troop_renown),
    (val_div, ":renown", 25),
    (try_begin),
      (gt, ":leadership", 0),
      (str_store_string, s2, "@ +"),
    (else_try),
      (str_store_string, s2, "@ "),
    (try_end),
    (try_begin),
      (gt, ":charisma", 0),
      (str_store_string, s3, "@ +"),
    (else_try),
      (str_store_string, s3, "@ "),
    (try_end),
    (try_begin),
      (gt, ":renown", 0),
      (str_store_string, s4, "@ +"),
    (else_try),
      (str_store_string, s4, "@ "),
    (try_end),
    (assign, reg5, ":party_size_limit"),
    (assign, reg1, ":leadership"),
    (assign, reg2, ":charisma"),
    (assign, reg3, ":renown"),
    (str_store_string, s1, "@Current party size limit is {reg5}.^Current party size modifiers are:^^Base size:  +10^Leadership: {s2}{reg1}^Charisma: {s3}{reg2}^Renown: {s4}{reg3}^TOTAL:  {reg5}"),
    ],
    [
      ("continue",[],"Continue...",
       [(jump_to_menu, "mnu_reports"),
        ]
       ),
      ]
  ),


  ("camp",0,
   "You set up camp. What do you want to do?",
   "none",
   [(party_set_slot,'p_main_party',slot_party_icon_state, pis_normal),
#    (set_background_mesh, "mesh_pic_camp"),
    ],
    [
      ("camp_action_1",[(eq,"$cheat_mode",1)],"Cheat: Walk around.",
       [(set_jump_mission,"mt_ai_training"),
        (call_script, "script_setup_random_scene"),
        (change_screen_mission),
        ]
       ),
      ("camp_wait_here",[],"Wait here for some time.",
       [
           (assign,"$g_camp_mode", 1),
#           (assign,"$auto_menu","mnu_camp"),
           (party_set_slot,'p_main_party',slot_party_icon_state, pis_camping),
           (rest_for_hours_interactive, 72, 5, 1), #rest while attackable
           (change_screen_return),
        ]
       ),
      #("camp_recruit_prisoners",
      # [(troops_can_join, 1),
      #  (store_current_hours, ":cur_time"),
      #  (val_sub, ":cur_time", 24),
      #  (gt, ":cur_time", "$g_prisoner_recruit_last_time"),
      #  (try_begin),
      #    (gt, "$g_prisoner_recruit_last_time", 0),
      #    (assign, "$g_prisoner_recruit_troop_id", 0),
      #    (assign, "$g_prisoner_recruit_size", 0),
      #    (assign, "$g_prisoner_recruit_last_time", 0),
      #  (try_end),
      #  (assign, ":num_regular_prisoner_slots", 0),
      #  (party_get_num_prisoner_stacks, ":num_stacks", "p_main_party"),
      #  (try_for_range, ":cur_stack", 0, ":num_stacks"),
      #    (party_prisoner_stack_get_troop_id, ":cur_troop_id", "p_main_party", ":cur_stack"),
      #    (neg|troop_is_hero, ":cur_troop_id"),
      #    (val_add, ":num_regular_prisoner_slots", 1),
      #  (try_end),
      #  (gt, ":num_regular_prisoner_slots", 0),
      #  ], "Recruit from prisoners.",
      # [(jump_to_menu, "mnu_camp_recruit_prisoners"),
      #  ],
      # ),
      ("camp_cheat",
       [(eq, "$cheat_mode", 1)
        ], "CHEAT MENU!",
       [(jump_to_menu, "mnu_camp_cheat"),
        ],
       ),
      ("resume_travelling",[],"Resume travelling.",
       [
           (change_screen_return),
        ]
       ),
      ]
  ),
  ("camp_cheat",0,
   "Select a cheat:",
   "none",
   [],
    [
      ("camp_cheat_1",[],"Increase player renown.",
       [(str_store_string, s1, "@Player renown is increased by 100. "),
        (call_script, "script_change_troop_renown", "trp_player" ,100),
        (jump_to_menu, "mnu_camp_cheat"),
        ]
       ),
      ("camp_action_4",[],"Back to camp menu.",
       [(jump_to_menu, "mnu_camp"),
        ]
       ),
      ]
  ),


  (
    "pay_day",0,
    "{s1}.",
    "none",
    [
        (call_script, "script_calculate_player_faction_wage"),
        (assign, ":total_wages", reg0),
        (assign, reg6, ":total_wages"),

        (assign, reg2, "$g_player_debt_to_party_members"),
        (store_add, reg3, reg6, reg2),
        (store_troop_gold, ":player_wealth", "trp_player"),
        (assign, reg4, ":player_wealth"),

        (val_add, ":total_wages", "$g_player_debt_to_party_members"),

        (try_begin),
          (ge, ":player_wealth", ":total_wages"),
          (assign, "$g_player_debt_to_party_members", 0),
          (troop_remove_gold, "trp_player",":total_wages"),
          (store_sub, reg5, reg4, reg3),
          (str_store_string, s1, "@You paid {reg3} of your {reg4} mon to your men. You have {reg5} mon left."),
        (else_try),
          (troop_remove_gold, "trp_player",":player_wealth"),
          (store_sub, ":unpaid", ":total_wages", ":player_wealth"),
          (assign, reg5, ":unpaid"),
          (str_store_string, s1, "@Your debt to your men amounted to {reg3} mon, however you only had {reg4}. Unpaid sum of {reg5} mon is added as debt. Your party loses morale."),
          (val_add, "$g_player_debt_to_party_members", ":unpaid"),
        (try_end),

        (str_store_string, s1, "@This week's wages: {reg6} mon^Earlier debts: {reg2} mon^Total payment: {reg3} mon^Current wealth: {reg4} mon^^{s1}"),
        (call_script, "script_process_player_party_morale"),
    ],
    [
      ("continue",[],"Continue...",
       [
        (change_screen_return,0),
        ]
       ),
    ]
  ),

  
  (
    "simple_encounter",mnf_enable_hot_keys,
    "{s2} You have {reg10} troops fit for battle against their {reg11}.",
    "none",
    [
        (assign, "$g_enemy_party", "$g_encountered_party"),
        (assign, "$g_ally_party", -1),
        (call_script, "script_encounter_calculate_fit"),
        (try_begin),
          (eq, "$new_encounter", 1),
          (assign, "$new_encounter", 0),
          (assign, "$g_encounter_is_in_village", 0),
          (assign, "$g_encounter_type", 0),
          #(try_begin),
          #  (party_slot_eq, "$g_enemy_party", slot_party_ai_state, spai_raiding_village),
          #  (party_get_slot, ":village_no", "$g_enemy_party", slot_party_ai_object),
          #  (store_distance_to_party_from_party, ":dist", ":village_no", "$g_enemy_party"),
          #  (try_begin),
          #    (lt, ":dist", raid_distance),
          #    (assign, "$g_encounter_is_in_village", ":village_no"),
          #    (assign, "$g_encounter_type", enctype_fighting_against_village_raid),
          #  (try_end),
          #(try_end),
          #(try_begin),
          #  (gt, "$g_player_raiding_village", 0),
          #  (assign, "$g_encounter_is_in_village", "$g_player_raiding_village"),
          #  (assign, "$g_encounter_type", enctype_catched_during_village_raid),
          #  (party_quick_attach_to_current_battle, "$g_encounter_is_in_village", 1), #attach as enemy
          #  (str_store_string, s1, "@Villagers"),
          #  (display_message, "str_s1_joined_battle_enemy"),
          #(else_try),
          #  (eq, "$g_encounter_type", enctype_fighting_against_village_raid),
          #  (party_quick_attach_to_current_battle, "$g_encounter_is_in_village", 0), #attach as friend
          #  (str_store_string, s1, "@Villagers"),
          #  (display_message, "str_s1_joined_battle_friend"),
          #  # Let village party join battle at your side
          #(try_end),
          (call_script, "script_let_nearby_parties_join_current_battle"),
          (call_script, "script_encounter_init_variables"),
          (assign, "$encountered_party_hostile", 0),
          (assign, "$encountered_party_friendly", 0),
          (try_begin),
            (party_slot_ge,"$g_encountered_party",slot_spawn_att_to_player,att_cautious),
            (assign, "$encountered_party_friendly", 1),
          (try_end),
          (try_begin),
            (party_slot_lt,"$g_encountered_party",slot_spawn_att_to_player,att_cautious),
            (assign, "$encountered_party_hostile", 1),
            (try_begin),
              (encountered_party_is_attacker),
              (assign, "$cant_leave_encounter", 1),
            (try_end),
          (try_end),
          (assign, "$g_talk_context", tc_party_encounter),
          (call_script, "script_setup_party_meeting", "$g_encountered_party"),
        (else_try), #second or more turn
#          (try_begin),
#            (call_script, "script_encounter_calculate_morale_change"),
#          (try_end),
          (try_begin),
            # We can leave battle only after some troops have been killed. 
            (eq, "$cant_leave_encounter", 1),
            (call_script, "script_party_count_fit_regulars", "p_main_party_backup"),
            (assign, ":org_total_party_counts", reg0),
            (call_script, "script_party_count_fit_regulars", "p_encountered_party_backup"),
            (val_add, ":org_total_party_counts", reg0),

            (call_script, "script_party_count_fit_regulars", "p_main_party"),
            (assign, ":cur_total_party_counts", reg0),
            (call_script, "script_party_count_fit_regulars", "p_collective_enemy"),
            (val_add, ":cur_total_party_counts", reg0),

            (store_sub, ":leave_encounter_limit", ":org_total_party_counts", 10),
            (lt, ":cur_total_party_counts", ":leave_encounter_limit"),
            (assign, "$cant_leave_encounter", 0),
          (try_end),
          (eq, "$g_leave_encounter",1),
          (change_screen_return),
        (try_end),

        #setup s2
        (str_store_party_name, s1,"$g_encountered_party"),
        (try_begin),
          (eq, "$g_encounter_type", 0),
          (str_store_string, s2,"@You have encountered {s1}."),
        #(else_try),
        #  (eq, "$g_encounter_type", enctype_fighting_against_village_raid),
        #  (str_store_party_name, s3, "$g_encounter_is_in_village"),
        #  (str_store_string, s2,"@You have engaged {s1}, while they were raiding {s3}."),
        #(else_try),
        #  (eq, "$g_encounter_type", enctype_catched_during_village_raid),
        #  (str_store_party_name, s3, "$g_encounter_is_in_village"),
        #  (str_store_string, s2,"@You were caught by {s1}, while your forces were raiding {s3}."),
        (try_end),
        (try_begin),
          (call_script, "script_party_count_fit_regulars","p_collective_enemy"),
          (assign, ":num_enemy_regulars_remaining", reg0),
          (assign, ":enemy_finished",0),
          (try_begin),
            (eq, "$g_battle_result", 1),
            (eq, ":num_enemy_regulars_remaining", 0), #battle won
            (assign, ":enemy_finished",1),
          (else_try),
            (eq, "$g_engaged_enemy", 1),
            (le, "$g_enemy_fit_for_battle",0),
            (ge, "$g_friend_fit_for_battle",1),
            (assign, ":enemy_finished",1),
          (try_end),
          (this_or_next|eq, ":enemy_finished",1),
          (eq,"$g_enemy_surrenders",1),
          (assign, "$g_next_menu", -1),
          (jump_to_menu, "mnu_total_victory"),
        (else_try),
#          (eq, "$encountered_party_hostile", 1),
          (call_script, "script_party_count_fit_regulars","p_main_party"),
          (assign, reg3, reg0),
          (assign, ":friends_finished",0),
          (try_begin),
            (eq, "$g_battle_result", -1),
            (eq, reg3, 0), #battle lost
            (assign,  ":friends_finished",1),
          (else_try),
            (eq, "$g_engaged_enemy", 1),
            (ge, "$g_enemy_fit_for_battle",1),
            (le, "$g_friend_fit_for_battle",0),
            (assign,  ":friends_finished",1),
          (try_end),
          (this_or_next|eq,  ":friends_finished",1),
          (eq,"$g_player_surrenders",1),
          (assign, "$g_next_menu", "mnu_captivity_start_wilderness"),
          (jump_to_menu, "mnu_total_defeat"),
        (try_end),

       
        (try_begin),
          (this_or_next|eq, "$g_encountered_party_template", "pt_river_pirates"),
          (this_or_next|eq, "$g_encountered_party_template", "pt_forest_bandits"),
          (eq, "$g_encountered_party_template", "pt_mountain_bandits"),
          #(set_background_mesh, "mesh_pic_bandits"),
        (try_end),
    ],
    [
      ("encounter_attack",[
          (eq, "$encountered_party_friendly", 0),
          (store_troop_health,':player_health','trp_player'),
          (ge,':player_health',5),
          ],
                            "Charge the enemy.",[
                                (assign, "$g_battle_result", 0),
                                (assign, "$g_engaged_enemy", 1),
                                (call_script, "script_calculate_renown_value"),
                                (call_script, "script_calculate_battle_advantage"),
                                (set_battle_advantage, reg0),
                                (set_party_battle_mode),
                                #(try_begin),
                                #  (eq, "$g_encounter_type", enctype_fighting_against_village_raid),
                                #  (set_jump_mission,"mt_village_raid"),
                                #  (party_get_slot, ":scene_to_use", "$g_encounter_is_in_village", slot_castle_exterior),
                                #  (jump_to_scene, ":scene_to_use"),
                                #(else_try),
                                #  (eq, "$g_encounter_type", enctype_catched_during_village_raid),
                                #  (set_jump_mission,"mt_village_raid"),
                                #  (party_get_slot, ":scene_to_use", "$g_encounter_is_in_village", slot_castle_exterior),
                                #  (jump_to_scene, ":scene_to_use"),
                                #(else_try),
                                  (set_jump_mission,"mt_lead_charge"),
                                  (call_script, "script_setup_random_scene"),
                                #(try_end),
                                (assign, "$g_next_menu", "mnu_simple_encounter"),
                                (jump_to_menu, "mnu_battle_debrief"),
                                (change_screen_mission),
                                ]),
      ("encounter_order_attack",
		[
			  (eq, "$encountered_party_friendly", 0),
			  (call_script, "script_party_count_fit_regulars", "p_main_party"),
			  (ge, reg0, 2),
			  ],
        "Order your troops to attack as you stay back.",
		[
			(jump_to_menu,"mnu_order_attack_begin"),
			]),
      ("encounter_leave",[
          (eq,"$cant_leave_encounter", 0),
          ],"Leave.",[(leave_encounter),(change_screen_return)]),
      ("encounter_surrender",[
         (eq,"$cant_leave_encounter", 1),
          ],"Surrender.",[(assign,"$g_player_surrenders",1)]),
    ]
  ),
  (
    "order_attack_begin",0,
    "Your troops are ready to attack the enemy...",
    "none",
    [],
    [
      ("order_attack_begin",[],"Order the attack to begin.", [
                                    (assign, "$g_engaged_enemy", 1),
                                    (jump_to_menu,"mnu_order_attack_2"),
                                    ]),
      ("call_back",[],"Call them back.",[(jump_to_menu,"mnu_simple_encounter")]),
    ]
  ),
  (
    "order_attack_2",0,
    "{s4}^^Your casualties: {s8}^^Enemy casualties: {s9}",
    "none",
    [
                                    (call_script, "script_party_calculate_regular_strength", "p_main_party"),
                                    (assign, ":player_party_strength", reg0),
                                    (val_div, ":player_party_strength", 5),
                                    (call_script, "script_party_calculate_regular_strength", "p_collective_enemy"),
                                    (assign, ":enemy_party_strength", reg0),
                                    (val_div, ":enemy_party_strength", 5),
                                    
#                                    (call_script,"script_inflict_casualties_to_party", "p_main_party", ":enemy_party_strength"),
                                    (inflict_casualties_to_party_group, "p_main_party", ":enemy_party_strength", "p_temp_casualties"),
                                    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
                                    (str_store_string_reg, s8, s0),
                                    
####                                    (call_script,"script_inflict_casualties_to_party", "$g_encountered_party", ":player_party_strength"),
                                    (inflict_casualties_to_party_group, "$g_encountered_party", ":player_party_strength", "p_temp_casualties"),
                                    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
                                    (str_store_string_reg, s9, s0),

                                    (party_collect_attachments_to_party, "$g_encountered_party", "p_collective_enemy"),


 #                                   (assign, "$cant_leave_encounter", 0),

                                    (assign, "$no_soldiers_left", 0),
                                    (try_begin),
                                      (call_script, "script_party_count_fit_regulars","p_main_party"),
                                      (le, reg0, 0),
                                      (assign, "$no_soldiers_left", 1),
                                      (str_store_string, s4, "str_order_attack_failure"),
                                    (else_try),
                                      (call_script, "script_party_count_fit_regulars","p_collective_enemy"),
                                      (le, reg0, 0),
                                      (assign, ":continue", 0),
                                      (party_get_num_companion_stacks, ":party_num_stacks", "p_collective_enemy"),
                                      (try_begin),
                                        (eq, ":party_num_stacks", 0),
                                        (assign, ":continue", 1),
                                      (else_try),
                                        (party_stack_get_troop_id, ":party_leader", "p_collective_enemy", 0),
                                        (neg|troop_is_hero, ":party_leader"),
                                        (assign, ":continue", 1),
                                      (try_end),
                                      (eq, ":continue", 1),
                                      (assign, "$g_battle_result", 1),
                                      (assign, "$no_soldiers_left", 1),
                                      (str_store_string, s4, "str_order_attack_success"),
                                    (else_try),
                                      (str_store_string, s4, "str_order_attack_continue"),
                                    (try_end),
    ],
    [
      ("order_attack_continue",[(eq,  "$no_soldiers_left", 0)],"Order your soldiers to continue the attack.",[
          (jump_to_menu,"mnu_order_attack_2"),
          ]),
      ("order_retreat",[(eq,  "$no_soldiers_left", 0)],"Call your soldiers back.",[
          (jump_to_menu,"mnu_simple_encounter"),
          ]),
      ("continue",[(eq,  "$no_soldiers_left", 1)],"Continue...",[
          (jump_to_menu,"mnu_simple_encounter"),
          ]),
    ]
  ),

  (
    "battle_debrief",0,
    "{s11} Casualties are:^^Your Casualties:{s8}{s10}^^Enemy Casualties::{s9}",
    "none",
    [(try_begin),
       (eq, "$g_battle_result", 1),
       (call_script, "script_change_troop_renown", "trp_player", "$battle_renown_value"),
     (try_end),

     (call_script, "script_encounter_calculate_fit"),
     (try_begin),
       (eq, "$g_battle_result", 1),
       (eq, "$g_enemy_fit_for_battle", 0),
       (str_store_string, s11, "@You were victorious!"),
     (else_try),
       (eq, "$g_battle_result", -1),
       (ge, "$g_enemy_fit_for_battle",1),
       (le, "$g_friend_fit_for_battle",0),
       (str_store_string, s11, "@Battle is lost. Your forces were utterly crushed."),
     (else_try),
       (eq, "$g_battle_result", -1),
       (str_store_string, s11, "@Your companions carry you away from the fighting."),
     (else_try),
       (eq, "$g_battle_result", 1),
       (str_store_string, s11, "@You have defeated the enemy."),
     (else_try),
       (eq, "$g_battle_result", 0),
       (str_store_string, s11, "@You have retreated from the fight."),
     (try_end),

     (call_script, "script_print_casualties_to_s0", "p_player_casualties", 0),
     (str_store_string_reg, s8, s0),
     (call_script, "script_print_casualties_to_s0", "p_enemy_casualties", 0),
     (str_store_string_reg, s9, s0),
     (str_clear, s10),
     (try_begin),
       (eq, "$any_allies_at_the_last_battle", 1),
       (call_script, "script_print_casualties_to_s0", "p_ally_casualties", 0),
       (str_store_string, s10, "@^^Ally Casualties:{s0}"),
     (try_end),
     ],
    [
      ("continue",[],"Continue...",[(jump_to_menu, "$g_next_menu"),]),
    ]
  ),


  
  (
    "total_victory",0,
    "You shouldn't be reading this... {s9}",
    "none",
    [
        # We exploit the menu condition system below.
        # The conditions should make sure that always another screen or menu is called.
        (assign, ":done", 0),
        (try_begin),
          # Talk to ally leader
          (eq, "$thanked_by_ally_leader", 0),
          (assign, "$thanked_by_ally_leader", 1),
          (gt, "$g_ally_party", 0),

#          (store_add, ":total_str_without_player", "$g_starting_strength_ally_party", "$g_starting_strength_enemy_party"),
          
          (store_add, ":total_str_without_player", "$g_starting_strength_friends", "$g_starting_strength_enemy_party"),
          (val_sub, ":total_str_without_player", "$g_starting_strength_main_party"),

          (store_sub, ":ally_strength_without_player", "$g_starting_strength_friends", "$g_starting_strength_main_party"),
        
          (store_mul, ":ally_advantage", ":ally_strength_without_player", 100),
          (val_div, ":ally_advantage", ":total_str_without_player"),
          #Ally advantage=50  means battle was evenly matched

          (store_sub, ":enemy_advantage", 100, ":ally_advantage"),
        
          (store_mul, ":faction_reln_boost", ":enemy_advantage", "$g_starting_strength_enemy_party"),
          (val_div, ":faction_reln_boost", 3000),
          (val_min, ":faction_reln_boost", 4),

          (store_mul, "$g_relation_boost", ":enemy_advantage", ":enemy_advantage"),
          (val_div, "$g_relation_boost", 700),
        
          (party_get_num_companion_stacks, ":num_ally_stacks", "$g_ally_party"),
          (gt, ":num_ally_stacks", 0),
          (store_faction_of_party, ":ally_faction","$g_ally_party"),
          (store_relation, ":ally_reln",":ally_faction","fac_player_faction"),
          (store_add, ":new_ally_reln", ":ally_reln", ":faction_reln_boost"),
          (set_relation, ":ally_faction","fac_player_faction", ":new_ally_reln"),
          (party_stack_get_troop_id, ":ally_leader", "$g_ally_party"),
          (party_stack_get_troop_dna, ":ally_leader_dna", "$g_ally_party"),
          (try_begin),
            (troop_is_hero, ":ally_leader"),
            (troop_get_slot, ":hero_relation", ":ally_leader", slot_troop_player_relation),
            (assign, ":rel_boost", "$g_relation_boost"),
            (try_begin),
              (lt, ":hero_relation", -5),
              (val_div, ":rel_boost", 3),
            (try_end),
            (call_script,"script_change_player_relation_with_troop", ":ally_leader", ":rel_boost"),
          (try_end),
          (assign, "$g_talk_context", tc_ally_thanks),
		  (sanity_check),
		  (display_message,'@Talk context is tc_ally_thanks',debug_text),
          (call_script, "script_setup_troop_meeting",":ally_leader", ":ally_leader_dna"),
        (else_try),
          # Talk to enemy leaders
          (assign, ":done", 0),
          (party_get_num_companion_stacks, ":num_stacks", "p_encountered_party_backup"),
        
          (try_for_range, ":stack_no", "$last_defeated_hero", ":num_stacks"),
            (eq, ":done", 0),
            (party_stack_get_troop_id,   ":stack_troop","p_encountered_party_backup",":stack_no"),
            (party_stack_get_troop_dna,   ":stack_troop_dna","p_encountered_party_backup",":stack_no"),
            
            (troop_is_hero, ":stack_troop"),
            (store_add, "$last_defeated_hero", ":stack_no", 1),
        
            (troop_set_slot, ":stack_troop", slot_troop_is_prisoner, 0),
            (troop_set_slot, ":stack_troop", slot_troop_leaded_party, -1),
            (store_random_in_range, ":rand", 0, 100),
            (try_begin),
              (lt, ":rand", hero_escape_after_defeat_chance),
              (str_store_troop_name, s1, ":stack_troop"),
              (store_troop_faction, ":defeated_faction", ":stack_troop"),
              (str_store_faction_name, s3, ":defeated_faction"),
              (str_store_string,s17,"@{s1} of {s3} managed to escape."),
              (display_log_message,"@{s17}"),
              (jump_to_menu, "mnu_enemy_slipped_away"),
              (assign, ":done", 1),
            (else_try),
              (assign, "$g_talk_context", tc_hero_defeated),
              (call_script, "script_setup_troop_meeting",":stack_troop", ":stack_troop_dna"),
              (assign, ":done", 1),
            (try_end),
          (try_end),
          (eq, ":done", 1),
        (else_try),
          # Talk to freed heroes
          (assign, ":done", 0),
          (party_get_num_prisoner_stacks, ":num_prisoner_stacks","p_encountered_party_backup"),
          (try_for_range, ":stack_no", "$last_freed_hero", ":num_prisoner_stacks"),
            (eq, ":done", 0),
            (party_prisoner_stack_get_troop_id,   ":stack_troop","p_encountered_party_backup",":stack_no"),
            (troop_is_hero, ":stack_troop"),
            (party_prisoner_stack_get_troop_dna,   ":stack_troop_dna","p_encountered_party_backup",":stack_no"),
            (store_add, "$last_freed_hero", ":stack_no", 1),
            (assign, "$g_talk_context", tc_hero_freed),
            (call_script, "script_setup_troop_meeting",":stack_troop", ":stack_troop_dna"),
            (assign, ":done", 1),
          (try_end),
          (eq, ":done", 1),
        (else_try),
          (eq, "$capture_screen_shown", 0),
          (assign, "$capture_screen_shown", 1),
          (party_clear, "p_temp_party"),
          (assign, "$g_move_heroes", 0),
          (call_script, "script_party_prisoners_add_party_companions", "p_temp_party", "p_collective_enemy"),
          (call_script, "script_party_add_party_prisoners", "p_temp_party", "p_collective_enemy"),

          (try_begin),
            (call_script, "script_party_calculate_strength", "p_collective_friends_backup"),
            (assign,":total_initial_strength", reg0),
            (gt, ":total_initial_strength", 0),
#            (gt, "$g_ally_party", 0),
            (call_script, "script_party_calculate_strength", "p_main_party_backup"),
            (assign,":player_party_initial_strength", reg0),
            # move ally_party_initial_strength/(player_party_initial_strength + ally_party_initial_strength) prisoners to ally party.
            # First we collect the share of prisoners of the ally party and distribute those among the allies.
            (store_sub, ":ally_party_initial_strength", ":total_initial_strength", ":player_party_initial_strength"),

#            (call_script, "script_party_calculate_strength", "p_ally_party_backup"),
#            (assign,":ally_party_initial_strength", reg0),
#            (store_add, ":total_initial_strength", ":player_party_initial_strength", ":ally_party_initial_strength"),
            (store_mul, ":ally_share", ":ally_party_initial_strength", 1000),
            (val_div, ":ally_share", ":total_initial_strength"),
            (assign, "$pin_number", ":ally_share"), #we send this as a parameter to the script.
            (party_clear, "p_temp_party_2"),
            (call_script, "script_move_members_with_ratio", "p_temp_party", "p_temp_party_2"),
        
            #TODO: This doesn't handle prisoners if our allies joined battle after us.
            (try_begin),
              (gt, "$g_ally_party", 0),
              (distribute_party_among_party_group, "p_temp_party_2", "$g_ally_party"),
            (try_end),
             #next if there's anything left, we'll open up the party exchange screen and offer them to the player.
          (try_end),
          (party_get_num_companions, ":num_rescued_prisoners", "p_temp_party"),
          (party_get_num_prisoners,  ":num_captured_enemies", "p_temp_party"),
          (store_add, ":total_capture_size", ":num_rescued_prisoners", ":num_captured_enemies"),
          (gt, ":total_capture_size", 0),
          (change_screen_exchange_with_party, "p_temp_party"),
        (else_try),
          (eq, "$loot_screen_shown", 0),
          (assign, "$loot_screen_shown", 1),
          (try_begin),
            (gt, "$g_ally_party", 0),
            (call_script, "script_party_add_party", "$g_ally_party", "p_temp_party"), #Add remaining prisoners to ally TODO: FIX it.
          (else_try),
            (party_get_num_attached_parties, ":num_quick_attachments", "p_main_party"),
            (gt, ":num_quick_attachments", 0),
            (party_get_attached_party_with_rank, ":helper_party", "p_main_party", 0),
            (call_script, "script_party_add_party", ":helper_party", "p_temp_party"), #Add remaining prisoners to our reinforcements
          (try_end),
          (troop_clear_inventory, "trp_temp_troop"),
          (call_script, "script_party_calculate_loot", "p_encountered_party_backup"),
          (gt, reg0, 0),
          (change_screen_loot, "trp_temp_troop"),
        (else_try),
          #finished all
          (try_begin),
#            (gt, "$g_ally_party", 0),
            (end_current_battle),
          (try_end),
          (call_script, "script_party_give_xp_and_gold", "p_encountered_party_backup"),
          (try_begin),
            (eq, "$g_enemy_party", 0),
            (display_message,"str_error_string"),
          (try_end),
          (call_script, "script_clear_party_group", "$g_enemy_party"),
          (try_begin),
            (eq, "$g_next_menu", -1),
            (leave_encounter),
            (change_screen_return),
          (else_try),
            (jump_to_menu, "$g_next_menu"),
          (try_end),
        (try_end),
      ],
    [
      ("continue",[],"Continue...",[]),
        ]
  ),

  (
    "enemy_slipped_away",0,
    "{s17}",
    "none",
    [],
    [
      ("continue",[],"Continue...",[(jump_to_menu,"mnu_total_victory")]),
    ]
  ),

  (
    "total_defeat",0,
    "You shouldn't be reading this...",
    "none",
    [
           # Free prisoners
          (party_get_num_prisoner_stacks, ":num_prisoner_stacks","p_main_party"),
          (try_for_range, ":stack_no", 0, ":num_prisoner_stacks"),
            (party_prisoner_stack_get_troop_id, ":stack_troop","p_main_party",":stack_no"),
            (troop_is_hero, ":stack_troop"),
            (troop_set_slot, ":stack_troop", slot_troop_is_prisoner, 0),
          (try_end),

          (troop_get_inventory_capacity, ":inv_cap", "trp_player"),
          (try_for_range, ":i_slot", 0, ":inv_cap"),
            (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
            (ge, ":item_id", 0),
            (troop_get_inventory_slot_modifier, ":item_modifier", "trp_player", ":i_slot"),
            (try_begin),
              (is_between, ":item_id", trade_goods_begin, trade_goods_end),
              (assign, ":randomness", 20),
            (else_try),
              (is_between, ":item_id", horses_begin, horses_end),
              (assign, ":randomness", 15),
            (else_try),
              (this_or_next|is_between, ":item_id", weapons_begin, weapons_end),
              (is_between, ":item_id", ranged_weapons_begin, ranged_weapons_end),
              (assign, ":randomness", 5),
            (else_try),
              (is_between, ":item_id", armors_begin, armors_end),
              (assign, ":randomness", 5),
            (try_end),
            (store_random_in_range, ":random_no", 0, 100),
            (lt, ":random_no", ":randomness"),
            (troop_remove_item, "trp_player", ":item_id"),
            
            (party_get_slot, ":cur_loot_slot", "$g_enemy_party", slot_party_next_looted_item_slot),
            (val_add, ":cur_loot_slot", slot_party_looted_item_1),
            (party_set_slot, "$g_enemy_party", ":cur_loot_slot", ":item_id"),
            (val_sub, ":cur_loot_slot", slot_party_looted_item_1),
            (val_add, ":cur_loot_slot", slot_party_looted_item_1_modifier),
            (party_set_slot, "$g_enemy_party", ":cur_loot_slot", ":item_modifier"),
            (val_sub, ":cur_loot_slot", slot_party_looted_item_1_modifier),
            (val_add, ":cur_loot_slot", 1),
            (val_mod, ":cur_loot_slot", num_party_loot_slots),
            (party_set_slot, "$g_enemy_party", slot_party_next_looted_item_slot, ":cur_loot_slot"),
           (try_end),

          (store_troop_gold, ":cur_gold", "trp_player"),
          (store_div, ":max_lost", ":cur_gold", 4),
          (store_div, ":min_lost", ":cur_gold", 10),
          (store_random_in_range, ":lost_gold", ":min_lost", ":max_lost"),
          (troop_remove_gold, "trp_player", ":lost_gold"),

          (assign, "$g_move_heroes", 0),
          (party_clear, "p_temp_party"),
          (call_script, "script_party_add_party_prisoners", "p_temp_party", "p_main_party"),
          (call_script, "script_party_prisoners_add_party_companions", "p_temp_party", "p_main_party"),
          (distribute_party_among_party_group, "p_temp_party", "$g_enemy_party"),
        
          (call_script, "script_party_remove_all_companions", "p_main_party"),
          (assign, "$g_move_heroes", 1),
          (call_script, "script_party_remove_all_prisoners", "p_main_party"),

          (try_begin),
            (eq, "$g_next_menu", -1),
            (leave_encounter),
            (change_screen_return),
          (else_try),
            (jump_to_menu, "$g_next_menu"),
          (try_end),
          (try_begin),
            (gt, "$g_ally_party", 0),
            (call_script, "script_party_wound_all_members", "$g_ally_party"),
          (try_end),
      ],
    []
  ),
  
  (
    "pre_join",0,
    "You come accross a battle where {s2} are attacking {s1}. You decide to...",
    "none",
    [
        (str_store_party_name, 1,"$g_encountered_party"),
        (str_store_party_name, 2,"$g_encountered_party_2"),
      ],
    [
      ("pre_join_help_attackers",[
          (store_faction_of_party, ":attacker_faction", "$g_encountered_party_2"),
          (store_relation, ":attacker_relation", ":attacker_faction", "fac_player_faction"),
          (store_faction_of_party, ":defender_faction", "$g_encountered_party"),
          (store_relation, ":defender_relation", ":defender_faction", "fac_player_faction"),
          (ge, ":attacker_relation", -1),
          (le, ":defender_relation", -1),
          ],
          "Go and help the {s2}.",[
              (select_enemy,0),
              (assign,"$g_enemy_party","$g_encountered_party"),
              (assign,"$g_ally_party","$g_encountered_party_2"),
              (jump_to_menu,"mnu_join_battle")]),
      ("pre_join_help_defenders",[
          (store_faction_of_party, ":attacker_faction", "$g_encountered_party_2"),
          (store_relation, ":attacker_relation", ":attacker_faction", "fac_player_faction"),
          (store_faction_of_party, ":defender_faction", "$g_encountered_party"),
          (store_relation, ":defender_relation", ":defender_faction", "fac_player_faction"),
          (ge, ":defender_relation", -1),
          (le, ":attacker_relation", -1),
          ],
          "Rush to the aid of the {s1}.",[
              (select_enemy,1),
              (assign,"$g_enemy_party","$g_encountered_party_2"),
              (assign,"$g_ally_party","$g_encountered_party"),
              (jump_to_menu,"mnu_join_battle")]),
      ("pre_join_leave",[],"Don't get involved.",[(leave_encounter),(change_screen_return)]),
    ]
  ),
  (
    "join_battle",0,
    "You are helping the {s2} against the {s1}. You have {reg10} troops fit for battle against the enemy's {reg11}.",
    "none",
    [
        (str_store_party_name, 1,"$g_enemy_party"),
        (str_store_party_name, 2,"$g_ally_party"),

        (call_script, "script_encounter_calculate_fit"),

        (try_begin),
          (eq, "$new_encounter", 1),
          (assign, "$new_encounter", 0),
          (call_script, "script_encounter_init_variables"),
##          (assign, "$capture_screen_shown", 0),
##          (assign, "$loot_screen_shown", 0),
##          (assign, "$g_battle_result", 0),
##          (assign, "$cant_leave_encounter", 0),
##          (assign, "$last_defeated_hero", 0),
##          (assign, "$last_freed_hero", 0),
##          (call_script, "script_party_copy", "p_main_party_backup", "p_main_party"),
##          (call_script, "script_party_copy", "p_encountered_party_backup", "p_collective_enemy"),
##          (call_script, "script_party_copy", "p_ally_party_backup", "p_collective_ally"),
        (else_try), #second or more turn
          (eq, "$g_leave_encounter",1),
          (change_screen_return),
        (try_end),

        (try_begin),
          (call_script, "script_party_count_fit_regulars","p_collective_enemy"),
          (assign, ":num_enemy_regulars_remaining", reg0),
          (assign, ":enemy_finished",0),
          (try_begin),
            (eq, "$g_battle_result", 1),
            (eq, ":num_enemy_regulars_remaining", 0), #battle won
            (assign, ":enemy_finished",1),
          (else_try),
            (eq, "$g_engaged_enemy", 1),
            (le, "$g_enemy_fit_for_battle",0),
            (ge, "$g_friend_fit_for_battle",1),
            (assign, ":enemy_finished",1),
          (try_end),
          (this_or_next|eq, ":enemy_finished",1),
          (eq,"$g_enemy_surrenders",1),
          (assign, "$g_next_menu", -1),
          (jump_to_menu, "mnu_total_victory"),
        (else_try),
#          (eq, "$encountered_party_hostile", 1),
          (call_script, "script_party_count_fit_regulars","p_collective_friends"),
          (assign, ":ally_num_soldiers", reg0),
          (assign, ":battle_lost", 0),
          (try_begin),
            (eq, "$g_battle_result", -1),
            (eq, ":ally_num_soldiers", 0), #battle lost
            (assign, ":battle_lost",1),
          (try_end),
          (this_or_next|eq, ":battle_lost",1),
          (eq,"$g_player_surrenders",1),
        # TODO: Split prisoners to all collected parties.
        # NO Need? Let default battle logic do it for us. 
#          (assign, "$g_move_heroes", 0),
#          (call_script, "script_party_add_party_prisoners", "$g_enemy_party", "p_collective_ally"),
#          (call_script, "script_party_prisoners_add_party_companions", "$g_enemy_party", "p_collective_ally"),
        #TODO: Clear all attached allies.
#          (call_script, "script_party_remove_all_companions", "$g_ally_party"),
#          (call_script, "script_party_remove_all_prisoners", "$g_ally_party"),
          (leave_encounter),
          (change_screen_return),
        (try_end),
      ],
    [
      ("join_attack",[
#          (neq, "$encountered_party_hostile", 0),
          (store_troop_health,reg5,"trp_player"),
          (ge,reg5,20),
          ],
                            "Charge the enemy.",[
                                (assign, "$g_battle_result", 0),
                                (call_script, "script_calculate_renown_value"),
                                (call_script, "script_calculate_battle_advantage"),
                                (set_battle_advantage, reg0),
                                (set_party_battle_mode),
                                (set_jump_mission,"mt_lead_charge"),
                                (call_script, "script_setup_random_scene"),
                                (assign, "$g_next_menu", "mnu_join_battle"),
                                (jump_to_menu, "mnu_battle_debrief"),
                                (change_screen_mission),
                                ]),

      ("join_order_attack",[
#          (gt, "$encountered_party_hostile", 0),
          (call_script, "script_party_count_fit_regulars", "p_main_party"),(ge, reg0, 2),
          ],
           "Order your troops to join your allies while you stay back.",[(jump_to_menu,"mnu_join_order_attack"),
                                                            ]),
      
#      ("join_attack",[],"Lead a charge against the enemies",[(set_jump_mission,"mt_charge_with_allies"),
#                                (call_script, "script_setup_random_scene"),
#                                                             (change_screen_mission,0)]),
      ("join_leave",[],"Leave.",[(leave_encounter),(change_screen_return)]),
    ]
  ),


  (
    "join_order_attack",0,
    "{s4}^^Your casualties: {s8}^^Allies' casualties: {s9}^^Enemy casualties: {s10}",
    "none",
    [
                                    (call_script, "script_party_calculate_regular_strength", "p_main_party"),
                                    (assign, ":player_party_strength", reg0),
                                    (val_div, ":player_party_strength", 5),
                                    (call_script, "script_party_calculate_regular_strength", "p_collective_friends"),
                                    (assign, ":friend_party_strength", reg0),
                                    (val_div, ":friend_party_strength", 5),
                                    
                                    (call_script, "script_party_calculate_regular_strength", "p_collective_enemy"),
                                    (assign, ":enemy_party_strength", reg0),
                                    (val_div, ":enemy_party_strength", 5),

                                    (assign, ":enemy_party_strength_for_p", ":enemy_party_strength"),
                                    (val_mul, ":enemy_party_strength_for_p", ":player_party_strength"),
                                    (val_div, ":enemy_party_strength_for_p", ":friend_party_strength"),

                                    (val_sub, ":enemy_party_strength", ":enemy_party_strength_for_p"),
                                    (inflict_casualties_to_party_group, "p_main_party", ":enemy_party_strength_for_p", "p_temp_casualties"),
                                    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
                                    (str_store_string_reg, s8, s0),
                                    
                                    (inflict_casualties_to_party_group, "$g_enemy_party", ":friend_party_strength", "p_temp_casualties"),
                                    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
                                    (str_store_string_reg, s10, s0),
                                    
                                    (call_script, "script_collect_friendly_parties"),
#                                    (party_collect_attachments_to_party, "$g_ally_party", "p_collective_ally"),

                                    (inflict_casualties_to_party_group, "$g_ally_party", ":enemy_party_strength", "p_temp_casualties"),
                                    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
                                    (str_store_string_reg, s9, s0),
                                    (party_collect_attachments_to_party, "$g_enemy_party", "p_collective_enemy"),

#                                    (assign, "$cant_leave_encounter", 0),
                                    (assign, "$no_soldiers_left", 0),
                                    (try_begin),
                                      (call_script, "script_party_count_fit_regulars","p_main_party"),
                                      (le, reg0, 0),
                                      (assign, "$no_soldiers_left", 1),
                                      (str_store_string, s4, "str_join_order_attack_failure"),
                                    (else_try),
                                      (call_script, "script_party_count_fit_regulars","p_collective_enemy"),
                                      (le, reg0, 0),
                                      (assign, "$g_battle_result", 1),
                                      (assign, "$no_soldiers_left", 1),
                                      (str_store_string, s4, "str_join_order_attack_success"),
                                    (else_try),
                                      (str_store_string, s4, "str_join_order_attack_continue"),
                                    (try_end),
    ],
    [
      ("continue",[],"Continue...",[
          (jump_to_menu,"mnu_join_battle"),
          ]),
    ]
  ),
############################################################################################################
#
# START ONIN NO RAN MENUS HERE
#
############################################################################################################

# Army upkeep menu - to be filled out later
(
	'army_upkeep',0,
	'You would pay upkeep costs for your garrisoned troops, but this is disabled for now',
	'none',
	[],
	[
		('army_upkeep_cont',[],'Continue...',[(change_screen_return)],'none'),
		],
	),
#Implement auto-detect for items in inventory with >= 3 in number
  (
    "merchant",0,
    "You set up your stall.",
    "none",
    [],
    [
      ("merchant_sell",[],"Open for business.",[(jump_to_menu,"mnu_merchant_2")]),
      ("merchant_end",[],"Close up shop.",[[leave_encounter],[change_screen_return]]),
     ]
   ),
#reg1 = num of item type, reg2 = item type, reg3 = trade skill level, reg(4) = num of item type modifier
#reg5 = num of items to sell, reg40 = items sold, reg(7) = total sales, reg(8) = price markup
#Algorithm: check if player has three or more of an item. Multiply the number of items by the trade skill
#factor, which equals trade_skill/10. This is the modifier of items sold, where the idea is that the higher one's
#trade skill is, the greater the total sellign percentage is. This modifier is subtracted from the total inventory,
#which becomes the basis for a randomly generated number of sales. The modifier is added back in, giving the total
#units sold. The value of the merchandise is stored in total_sales, which is subjected to a manditory 150% markup,
#plus an additional markup based on trade skill. The additional is a percentage of total sales, calculated as
#trade_skill/10, such that a player with 10 trade skill (the maximum) will sell all the goods put up for sale at
#300% of the item's original value.
  (
    "merchant_2",0,
    "What will be sold?",
    "none",
    [
        (try_for_range,':slot_no',slot_player_goods_1,(slot_player_goods_4+1)),
            (troop_set_slot,"trp_player",':slot_no',-1),
        (try_end),
        (try_begin),
            (assign,':slot_no',slot_player_goods_1),
            (assign,':loop_counter',0),
            (try_for_range,':item_no',items_begin,items_end),
				(lt,':loop_counter',4),
                (store_item_kind_count,':item_no_cnt',':item_no',"trp_player"),
                (ge,':item_no_cnt',3),
                (troop_set_slot,"trp_player",':slot_no',':item_no'),
                (val_add,':slot_no',1),
                (val_add,':loop_counter',1),
            (try_end),
        (try_end),
        ],
    [
      ("sell_goods_1",
		[
			(troop_get_slot,':item_no',"trp_player",slot_player_goods_1),
			(gt,':item_no',0),
			(str_store_item_name,s1,':item_no'),
			],
       "Sell {s1}.",
		[
			(troop_get_slot,':item_no',"trp_player",slot_player_goods_1),
			(store_item_kind_count,':item_no_cnt',':item_no',"trp_player"),
			(store_skill_level,':trade_skill',skl_trade,"trp_player"),
			(call_script,"script_generate_sales",':item_no',':item_no_cnt',':trade_skill'),
			(rest_for_hours,8,4,0),
			(finish_mission,0),
			(change_screen_return,0),
			]
		),
      ("sell_goods_2",
		[
			(troop_get_slot,':item_no',"trp_player",slot_player_goods_2),
			(gt,':item_no',0),
			(str_store_item_name,s1,':item_no'),
			],
       "Sell {s1}.",
       [
			(troop_get_slot,':item_no',"trp_player",slot_player_goods_2),
			(store_item_kind_count,':item_no_cnt',':item_no',"trp_player"),
			(store_skill_level,':trade_skill',skl_trade,"trp_player"),
			(call_script,"script_generate_sales",':item_no',':item_no_cnt',':trade_skill'),
			(rest_for_hours,8,4,0),
			(finish_mission,0),
			(change_screen_return,0),
			]
		),
      ("sell_goods_3",
		[
			(troop_get_slot,':item_no',"trp_player",slot_player_goods_3),
			(gt,':item_no',0),
			(str_store_item_name,s1,':item_no'),
			],
       "Sell {s1}.",
       [
			(troop_get_slot,':item_no',"trp_player",slot_player_goods_3),
			(store_item_kind_count,':item_no_cnt',':item_no',"trp_player"),
			(store_skill_level,':trade_skill',skl_trade,"trp_player"),
			(call_script,"script_generate_sales",':item_no',':item_no_cnt',':trade_skill'),
			(rest_for_hours,8,4,0),
			(finish_mission,0),
			(change_screen_return,0),
			]
		),
      ("sell_goods_4",
		[
			(troop_get_slot,':item_no',"trp_player",slot_player_goods_4),
			(gt,':item_no',0),
			(str_store_item_name,s1,':item_no'),
			],
       "Sell {s1}.",
       [
			(troop_get_slot,':item_no',"trp_player",slot_player_goods_4),
			(store_item_kind_count,':item_no_cnt',':item_no',"trp_player"),
			(store_skill_level,':trade_skill',skl_trade,"trp_player"),
			(call_script,"script_generate_sales",':item_no',':item_no_cnt',':trade_skill'),
			(rest_for_hours,8,4,0),
			(finish_mission,0),
			(change_screen_return,0),
			]
		),
      ("sell_nothing",[],
       "Sell nothing.",
       [(leave_encounter,0),(change_screen_return,0)]),
      ]
    ),
#city menu, guard positions are EP 5, 6, and 8. geomancer pos is EP 11
(
      "city",0,
      "{s1} {s2}.",
      "none",
      [
          (assign,'$g_town_has_dojo',false),
          (str_store_string,1,"str_enter_city"),
          (str_store_party_name,2,"$g_encountered_party"),
          (party_get_slot,reg20,"$g_encountered_party",slot_town_dojo),
          (try_begin),
			  (gt,reg20,0),
			  (assign,'$g_town_has_dojo',true),
		  (try_end),
		  (assign,'$g_most_recent_town','$g_encountered_party'),
          (call_script,"script_update_trade_good_price_for_party","$g_encountered_party"),
		  (call_script,'script_set_trade_good_price_for_party','$g_encountered_party'),
		  (set_price_rate_for_item_type,itp_type_goods,100),
		  (assign,'$ep_mode',ep_mode_first_entry),
          ],
      [
          # ('city_center',[],'Enter the city',[(modify_visitors_at_site,'scn_city'),
                                              # (reset_visitors),
                                              # (assign,reg1,'trp_samurai'),
                                              # (assign,reg2,'trp_t2_heavy_cav'),
                                              # (assign,reg3,'trp_yumi_ashigaru'),
                                              # (shuffle_range,1,4),
                                              # (set_visitor,5,reg1),
                                              # (set_visitor,6,reg2),
                                              # (set_visitor,8,reg3),
											  # (set_visitor,11,'trp_geomancer'),
											  # (try_begin),
													# (gt,reg20,0),
													# (assign,'$g_town_has_dojo',true),
											  # (try_end),
                                              # (set_jump_mission,'mt_visit_town_horseback'),
                                              # (set_jump_entry,1),
                                              # (jump_to_scene,'scn_city'),
                                              # (change_screen_mission)],
									# 'Return to the city.'),
		('city_south_ward',
		[],
		'Enter the south ward',
			[
				(modify_visitors_at_site,'scn_city_south_ward'),
				(reset_visitors),
				(call_script,'script_init_town_walkers'),
				(call_script,'script_calculate_ward_entry_point','scn_city_south_ward','$ep_mode'),
				(assign,':target_entry_no',reg0),
				(assign,'$ep_mode',ep_mode_within_city),
				(set_jump_mission,'mt_visit_town_horseback'),
				(set_jump_entry,':target_entry_no'),
				(jump_to_scene,'scn_city_south_ward'),
				(change_screen_mission),
				],'Enter the south ward'),
		('city_north_ward',
		[
			(eq,0,1),
			],
		'Enter the north ward',
			[
				(modify_visitors_at_site,'scn_city_south_ward'),
				(reset_visitors),
				(call_script,'script_init_town_walkers'),
				(call_script,'script_calculate_ward_entry_point','scn_city_north_ward','$ep_mode'),
				(assign,':target_entry_no',reg0),
				(set_jump_mission,'mt_visit_town_horseback'),
				(set_jump_entry,':target_entry_no'),
				(jump_to_scene,'scn_city_north_ward'),
				(change_screen_mission),
				],'Enter the north ward'),
		('city_east_ward',
		[
			(eq,0,1),
			],
		'Enter the east ward',
			[
				(party_get_slot,':broker','$g_encountered_party',slot_town_broker),
				(modify_visitors_at_site,'scn_city_east_ward'),
				(reset_visitors),
				(try_begin),
					(neq,':broker',null),
					(set_visitor,47,':broker'),
				(try_end),
				(call_script,'script_init_town_walkers'),
				(call_script,'script_calculate_ward_entry_point','scn_city_east_ward','$ep_mode'),
				(assign,':target_entry_no',reg0),
				(set_jump_mission,'mt_visit_town_horseback'),
				(set_jump_entry,':target_entry_no'),
				(jump_to_scene,'scn_city_east_ward'),
				(change_screen_mission),
				],'Enter the east ward'),
		('city_west_ward',
		[
			(eq,0,1),
			],
		'Enter the west ward',
			[
				(modify_visitors_at_site,'scn_city_west_ward'),
				(reset_visitors),
				(call_script,'script_init_town_walkers'),
				(call_script,'script_calculate_ward_entry_point','scn_city_west_ward','$ep_mode'),
				(assign,':target_entry_no',reg0),
				(set_jump_mission,'mt_visit_town_horseback'),
				(set_jump_entry,':target_entry_no'),
				(jump_to_scene,'scn_city_west_ward'),
				(change_screen_mission),
				],'Enter the west ward'),
          ('city_port_ward',
		[
			(eq,0,1),
			],
		'Enter the port',
			[
				(modify_visitors_at_site,'scn_city_west_ward'),
				(reset_visitors),
				(call_script,'script_init_town_walkers'),
				(call_script,'script_calculate_ward_entry_point','scn_city_west_ward','$ep_mode'),
				(assign,':target_entry_no',reg0),
				(set_jump_mission,'mt_visit_town_horseback'),
				(set_jump_entry,':target_entry_no'),
				(jump_to_scene,'scn_city_west_ward'),
				(change_screen_mission),
				],'Enter the port'),
          ("city_manor",
		  [
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_manor),
				],
		  "Enter the shinden.",
		  [
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_manor,1),
				(assign,'$shinden_main_hall_entrance',1),
				(assign,'$corridor_entry_point',1),
				(party_get_slot,':kokujin',"$g_encountered_party",slot_town_kokujin),
				(modify_visitors_at_site,'scn_shinden_main_hall'),
				(reset_visitors),
				(set_visitor,6,':kokujin'),
				(set_jump_mission,"mt_shinden"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_shinden_main_hall'),
				(change_screen_mission,0)],'Enter the manor.'),
          ("city_inn",
			[
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_inn),
			],
		  "Visit the inn.",
			[
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_inn,1),
				(party_get_slot,':innkeeper',"$g_encountered_party",slot_town_innkeeper),
				(modify_visitors_at_site,'scn_inn'),
				(reset_visitors),
				(set_visitor,2,':innkeeper'),
				(call_script,'script_modify_special_visitors','$g_encountered_party','scn_inn'),
				(set_jump_mission,"mt_town_default"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_inn'),
				(change_screen_mission,0),
			],'Enter the Inn.'),
          ("city_store",
		   [
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_merchant),
				],
		  "Visit the merchant hall.",
		  [
			(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_merchant,1),
			(party_get_slot,':merchant',"$g_encountered_party",slot_town_merchant),
			(party_get_slot,':moneychanger',"$g_encountered_party",slot_town_moneychanger),
			(party_get_slot,':fishmonger',"$g_encountered_party",slot_town_fishmonger),
			(modify_visitors_at_site,'scn_merchant_hall'),
            (reset_visitors),
			(set_visitor,2,':fishmonger'),
			(set_visitor,5,':merchant'),
			(set_visitor,4,':moneychanger'),
			(try_begin),
				(party_slot_neq,'$g_encountered_party',slot_town_broker,null),
				(party_get_slot,':broker',"$g_encountered_party",slot_town_broker),
				(set_visitor,3,':broker'),
			(try_end),
			(set_jump_mission,"mt_town_default"),
			(set_jump_entry,1),
			(jump_to_scene,'scn_merchant_hall'),
			(change_screen_mission,0)
			],
			'Visit the merchant'),
          ("city_smithy",
			[
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_smithy),
				],
		  "Visit the smithy.",
			[
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_smithy,1),
				(party_get_slot,':armorer',"$g_encountered_party",slot_town_armorer),
				(party_get_slot,':weaponsmith',"$g_encountered_party",slot_town_weaponsmith),
				(modify_visitors_at_site,'scn_smithy'),
				(reset_visitors),
				(set_visitor,3,':armorer'),
				(set_visitor,4,':weaponsmith'),
				(set_jump_mission,"mt_town_default"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_smithy'),
				(change_screen_mission,0)],'Visit the smithy'),
          ("city_dojo",
		  [
			(gt,reg20,0),
			# (eq,1,0),
			],
		  "Visit the dojo.",
           [
				(party_get_slot,'$g_town_sensei',"$g_encountered_party",slot_town_sensei),
               (assign,"$waiting_for_training_fight_result",-1),
               (modify_visitors_at_site,reg20),
               (reset_visitors),
			   (call_script,'script_modify_special_visitors','$g_encountered_party',reg20),
               (set_jump_mission,"mt_town_default"),
               (set_jump_entry,1),
               (jump_to_scene,reg20),
               (change_screen_mission,0)],
           'Enter the dojo'),
		   ('shinden_main_hall',
			[
				(eq,0,1),
				],
			'Enter the main hall',
			[
				(assign,reg1,1),
				(assign,'$corridor_entry_point',1),
				(assign,reg41,'$corridor_entry_point'),
				(display_message,'str_reg41'),
				(try_begin),
					(is_between,'$shinden_main_hall_entrance',2,6),
					(assign,reg1,'$shinden_main_hall_entrance'),
				(try_end),
				(party_get_slot,reg11,"$g_encountered_party",slot_town_kokujin),
				(modify_visitors_at_site,'scn_shinden_main_hall'),
				(reset_visitors),
				(set_visitor,6,reg11),
				(set_jump_mission,'mt_shinden'),
				(set_jump_entry,reg1),
				(jump_to_scene,'scn_shinden_main_hall'),
				(change_screen_mission),
				],
			'Enter the main hall'),
		('shinden_east_hall',
			[
				(eq,0,1),
				],
			'Enter the east hall',
			[
				(assign,'$corridor_entry_point',2),
				(modify_visitors_at_site,'scn_shinden_east_hall'),
				(reset_visitors),
				(call_script,'script_modify_special_visitors','$g_encountered_party','scn_shinden_east_hall'),
				(set_jump_mission,'mt_shinden'),
				(set_jump_entry,1),
				(jump_to_scene,'scn_shinden_east_hall'),
				(change_screen_mission),
				],
			'Enter the east hall'),
		('shinden_west_hall',
			[
				(eq,0,1),
				],
			'Enter the west hall',
			[
				(assign,'$corridor_entry_point',2),
				(modify_visitors_at_site,'scn_shinden_west_hall'),
				(reset_visitors),
				(call_script,'script_modify_special_visitors','$g_encountered_party','scn_shinden_west_hall'),
				(set_jump_mission,'mt_shinden'),
				(set_jump_entry,1),
				(jump_to_scene,'scn_shinden_west_hall'),
				(change_screen_mission),
				],
			'Enter the west hall'),
		('shinden_rear_hall_1',
			[
				(eq,0,1),
				],
			'Enter the rear hall',
			[
				(assign,'$corridor_entry_point',2),
				(try_begin),
					(party_slot_ge,"$g_encountered_party",slot_town_shugo,1),
					(modify_visitors_at_site,'scn_shinden_rear_hall'),
					(reset_visitors),
					(party_get_slot,reg12,"$g_encountered_party",slot_town_shugo),
					(set_visitor,7,reg12),
				(try_end),
				(set_jump_mission,'mt_shinden'),
				(set_jump_entry,1),
				(jump_to_scene,'scn_shinden_rear_hall'),
				(change_screen_mission),
				],
			'Enter the rear hall'),
		('shinden_rear_hall_2',
			[
				(eq,0,1),
				],
			'Enter the rear hall',
			[
				(assign,'$corridor_entry_point',2),
				(try_begin),
					(party_slot_ge,"$g_encountered_party",slot_town_shugo,1),
					(modify_visitors_at_site,'scn_shinden_rear_hall'),
					(reset_visitors),
					(party_get_slot,reg12,"$g_encountered_party",slot_town_shugo),
					(set_visitor,7,reg12),
				(try_end),
				(set_jump_mission,'mt_shinden'),
				(set_jump_entry,2),
				(jump_to_scene,'scn_shinden_rear_hall'),
				(change_screen_mission),
				],
			'Enter the rear hall'),
		('shinden_east_corridor',
			[
				(eq,0,1),
				],
			'Enter the east corridor',
			[
				(assign,'$shinden_main_hall_entrance',5),
				(set_jump_mission,'mt_shinden'),
				(set_jump_entry,'$corridor_entry_point'),
				(jump_to_scene,'scn_shinden_east_corridor'),
				(change_screen_mission),
				],
			'Enter the east corridor'),
		('shinden_west_corridor',
			[
				(eq,0,1),
				],
			'Enter the west corridor',
			[
				(assign,'$shinden_main_hall_entrance',2),
				(set_jump_mission,'mt_shinden'),
				(set_jump_entry,'$corridor_entry_point'),
				(jump_to_scene,'scn_shinden_west_corridor'),
				(change_screen_mission),
				],
			'Enter the west corridor'),
		('shinden_rear_corridor_1',
			[
				(eq,0,1),
				],
			'Enter the rear corridor',
			[
				(assign,'$shinden_main_hall_entrance',3),
				(set_jump_mission,'mt_shinden'),
				(set_jump_entry,'$corridor_entry_point'),
				(jump_to_scene,'scn_shinden_rear_corridor_1'),
				(change_screen_mission),
				],
			'Enter the rear corridor'),
		('shinden_rear_corridor_2',
			[
				(eq,0,1),
				],
			'Enter the rear corridor',
			[
				(assign,'$shinden_main_hall_entrance',4),
				(set_jump_mission,'mt_shinden'),
				(set_jump_entry,'$corridor_entry_point'),
				(jump_to_scene,'scn_shinden_rear_corridor_2'),
				(change_screen_mission),
				],
			'Enter the rear corridor'),
		('shinden_exit',
			[
				(eq,0,1),
				],
			'Leave the shinden',
			[
				(jump_to_menu,'mnu_city'),
				(set_jump_mission,'mt_town_default'),
				(set_jump_entry,7),
				(jump_to_scene,'scn_city'),
				(change_screen_mission),
				],
			'Leave'),
		("city_leave",[],"Leave.",
			[
				(try_begin),
					(check_quest_active,'qst_kengo_training'),
					(cancel_quest,'qst_kengo_training'),
				(try_end),
				(rest_for_hours,1,4,0),
				(leave_encounter,0),
				(change_screen_return,0)]),
          ],
      ),
(
	"town",0,
	"{s1} {s2}.",
	"none",
	[
		(assign,'$g_town_has_dojo',false),
		(str_store_string,1,"str_enter_town"),
		(str_store_party_name,2,"$g_encountered_party"),
		(party_get_slot,reg20,"$g_encountered_party",slot_town_dojo),
		(try_begin),
			(gt,reg20,0),
			(assign,'$g_town_has_dojo',true),
		(try_end),
		(assign,'$g_most_recent_town','$g_encountered_party'),
		(call_script,"script_update_trade_good_price_for_party",'$g_encountered_party'),
		(call_script,'script_set_trade_good_price_for_party','$g_encountered_party'),
		(set_price_rate_for_item_type,itp_type_goods,100),
        ],
	[
		('town_center',
			[],
			'Enter the town.',
			[
				(modify_visitors_at_site,'scn_town'),
				(reset_visitors),
				(call_script,'script_init_town_walkers'),
				(try_begin),
					(gt,reg20,0),
					(assign,'$g_town_has_dojo',true),
				(try_end),
				(set_jump_mission,'mt_visit_town_horseback'),
				(set_jump_entry,1),
				(jump_to_scene,'scn_town'),
				(change_screen_mission),
				],
			'Return to the city.'),
			("town_manor",
			[
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_manor),
				],
			"Visit the manor.",
			[
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_manor,1),
				(party_get_slot,':kokujin',"$g_encountered_party",slot_town_kokujin),
				(modify_visitors_at_site,'scn_manor'),
				(reset_visitors),
				(set_visitor,3,':kokujin'),
				(try_begin),
					(party_slot_ge,"$g_encountered_party",slot_town_shugo,1),
					(party_get_slot,reg12,"$g_encountered_party",slot_town_shugo),
					(set_visitor,4,reg12),
				(try_end),
				#(call_script,'script_modify_special_visitors','$g_encountered_party','scn_manor'),
				(set_jump_mission,"mt_town_default"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_manor'),
				(change_screen_mission,0),
				],
			"Visit the manor."),
			("town_inn",
			[
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_inn),
				],
			"Visit the inn.",
			[
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_inn,1),
				(party_get_slot,reg11,"$g_encountered_party",slot_town_innkeeper),
				(modify_visitors_at_site,'scn_inn'),
				(reset_visitors),
				(set_visitor,2,reg11),
				(call_script,'script_modify_special_visitors','$g_encountered_party','scn_inn'),
				(set_jump_mission,"mt_town_default"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_inn'),
				(change_screen_mission,0),
				],
			"Visit the inn."),
			("town_store",
			[
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_merchant),
				],
			"Visit the merchant.",
			[
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_merchant,1),
				(party_get_slot,':merchant',"$g_encountered_party",slot_town_merchant),
				(party_get_slot,':fishmonger',"$g_encountered_party",slot_town_fishmonger),
				(modify_visitors_at_site,'scn_merchant_hall'),
				(reset_visitors),
				(set_visitor,5,':merchant'),
				(set_visitor,2,':fishmonger'),
				(try_begin),
					(party_slot_neq,'$g_encountered_party',slot_town_moneychanger,null),
					(party_get_slot,':moneychanger',"$g_encountered_party",slot_town_moneychanger),
					(set_visitor,4,':moneychanger'),
				(try_end),
				(try_begin),
					(party_slot_neq,'$g_encountered_party',slot_town_broker,null),
					(party_get_slot,':broker',"$g_encountered_party",slot_town_broker),
					(set_visitor,3,':broker'),
				(try_end),
				(set_jump_mission,"mt_town_default"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_merchant_hall'),
				(change_screen_mission,0),
				],
			"Visit the merchant."),
          ("town_smithy",
			[
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_smithy),
				],
		  "Visit the smithy.",
			[
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_smithy,1),
				(party_get_slot,reg11,"$g_encountered_party",slot_town_armorer),
				(party_get_slot,reg12,"$g_encountered_party",slot_town_weaponsmith),
				(modify_visitors_at_site,'scn_smithy'),
				(reset_visitors),
				(set_visitor,3,reg11),
				(set_visitor,4,reg12),
				(set_jump_mission,"mt_town_default"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_smithy'),
				(change_screen_mission,0)],"Visit the smithy."),
          ("town_dojo",
		  [
			(gt,reg20,0),
			# (eq,0,1),
			],
		  "Visit the dojo.",
           [
              (party_get_slot,reg11,"$g_encountered_party",slot_town_sensei),
               (assign,"$waiting_for_training_fight_result",-1),
               (modify_visitors_at_site,reg20),
               (reset_visitors),
               (call_script,'script_modify_special_visitors','$g_encountered_party',reg20),
               (set_jump_mission,"mt_town_default"),
               (set_jump_entry,1),
               (jump_to_scene,reg20),
               (change_screen_mission,0)],"Visit the dojo."),
          ("town_leave",[],"Leave.",
			[
				(try_begin),
					(check_quest_active,'qst_kengo_training'),
					(cancel_quest,'qst_kengo_training'),
				(try_end),
				(rest_for_hours,1,4,0),
				(leave_encounter,0),
				(change_screen_return,0)]),
		],
      ),
(
	"village",0,
	"{s1} {s2}.",
	"none",
	[
		(try_begin),
			(neq,'$g_player_raiding_village','$g_current_town'),
			(assign,'$g_player_raiding_village', 0),
        (else_try),
			(jump_to_menu, "mnu_village_loot_continue"),
        (try_end),
		(try_begin),
          (eq, "$g_player_raid_complete", 1),
          (assign, "$g_player_raid_complete", 0),
          (jump_to_menu, "mnu_village_loot_complete"),
        (try_end),
        (assign,'$g_town_has_dojo',false),
		(str_store_string,1,"str_enter_village"),
		(str_store_party_name,2,"$g_encountered_party"),
		(party_get_slot,reg20,"$g_encountered_party",slot_town_dojo),
		(try_begin),
			(gt,reg20,0),
			(assign,'$g_town_has_dojo',true),
		(try_end),
		(assign,'$g_most_recent_town','$g_encountered_party'),
		(party_get_slot,':trade_good_price_array','$g_encountered_party',slot_town_trade_good_price_array),
		(assign,':array_index',0),
		(try_for_range,':item',trade_goods_begin,trade_goods_end),
			(call_script,'script_array_peek',':trade_good_price_array',':array_index'),
			(set_price_rate_for_item,':item','$return'),
			(val_add,':array_index',0),
		(try_end),
		(try_begin),
			(party_slot_eq,'$g_encountered_party',slot_town_lord,'trp_player'),
			(party_slot_ge,'$g_encountered_party',slot_town_accumulated_rents,1),
			(assign,'$g_menu_caller','mnu_village'),
			(jump_to_menu,'mnu_center_tax'),
		(try_end),
		(assign,'$default_menu','mnu_village'),
		#(jump_to_menu,'mnu_auto_return'),
		#(start_presentation,'prsnt_city_statistics'),
		],
      [
          ('village_center',
			[],
			'Enter the village.',
			[
				(modify_visitors_at_site,'scn_village'),
				(reset_visitors),
				(call_script,'script_init_town_walkers'),
				(set_jump_mission,'mt_visit_town_horseback'),
				(set_jump_entry,1),
				(try_begin),
					(gt,reg20,0),
					(assign,'$g_town_has_dojo',true),
				(try_end),
				(jump_to_scene,'scn_village'),
				(change_screen_mission),
				],
			'Return to the city.'),
			("village_manor",
			[
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_manor),
				],
			"Visit the manor.",
			[
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_manor,1),
				(party_get_slot,':kokujin',"$g_encountered_party",slot_town_kokujin),
				(modify_visitors_at_site,'scn_manor'),
				(reset_visitors),
				(set_visitor,3,':kokujin'),
				(set_jump_mission,"mt_town_default"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_manor'),
				(change_screen_mission,0),
				],
			"Visit the kokujin's office."),
			("village_inn",
			[
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_inn),
				],
			"Visit the inn.",
			[
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_inn,1),
				(party_get_slot,':innkeeper',"$g_encountered_party",slot_town_innkeeper),
				(modify_visitors_at_site,'scn_inn'),
				(reset_visitors),
				(set_visitor,2,':innkeeper'),
				(call_script,'script_modify_special_visitors','$g_encountered_party','scn_inn'),
				(set_jump_mission,"mt_town_default"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_inn'),
				(change_screen_mission,0),
				],
			"Visit the inn."),
			("village_store",
			[
				# (call_script,'script_cf_object_flag_set',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_merchant),
				],
			"Visit the merchant.",
			[
				(call_script,'script_object_set_flag',obj_party,'$g_encountered_party',slot_town_scene_flags,scn_flag_merchant,1),
				(party_get_slot,':merchant',"$g_encountered_party",slot_town_merchant),
				(party_get_slot,':fishmonger','$g_encountered_party',slot_town_fishmonger),
				(modify_visitors_at_site,'scn_store'),
				(reset_visitors),
				(set_visitor,4,':merchant'),
				(set_visitor,5,':fishmonger'),
				(set_jump_mission,"mt_town_default"),
				(set_jump_entry,1),
				(jump_to_scene,'scn_store'),
				(change_screen_mission,0),
				],
			"Visit the merchant."),
          ("village_dojo",
		  [
			(gt,reg20,0),
			# (eq,0,1),
			],
		  "Visit the dojo.",
           [
              (party_get_slot,reg11,"$g_encountered_party",slot_town_sensei),
               (assign,"$waiting_for_training_fight_result",-1),
               (modify_visitors_at_site,reg20),
               (reset_visitors),
              (call_script,'script_modify_special_visitors','$g_encountered_party',reg20),
               (set_jump_mission,"mt_town_default"),
               (set_jump_entry,1),
               (jump_to_scene,reg20),
               (change_screen_mission,0)],"Visit the dojo."),
		  ('village_loot',
			[
				(party_slot_eq,'$g_encountered_party',slot_town_state,sts_normal),
				(store_faction_of_party,':faction','$g_encountered_party'),
				(store_relation,':relation','fac_player_faction',':faction'),
				(lt,':relation',0),
				],
			'Loot and burn this village',
			[
				(jump_to_menu,'mnu_village_start_attack'),
				]),
          ("village_leave",[],"Leave.",
			[
				(try_begin),
					(check_quest_active,'qst_kengo_training'),
					(cancel_quest,'qst_kengo_training'),
				(try_end),
				(rest_for_hours,1,4,0),
				(leave_encounter,0),
				(change_screen_return,0)]),
          ]
      ),
("village_start_attack",0,
    "Some of the villagers grab their farming tools and prepare to resist you.",
    "none",
	[
		(call_script, "script_party_count_fit_regulars","p_main_party"),
		(assign, ":player_party_size", reg0),
		(call_script, "script_party_count_fit_regulars","$g_current_town"),
		(assign, ":villagers_party_size", reg0),
		(store_div,':size_ratio',':player_party_size',':villagers_party_size'),
		(try_begin),
			(ge, ":size_ratio", 3),
			(jump_to_menu, "mnu_village_loot_no_resist"),
		(else_try),
			(this_or_next|eq, ":villagers_party_size", 0),
			(eq, "$g_battle_result", 1),
			(try_begin),
				(eq, "$g_battle_result", 1),
				(store_random_in_range, ":emnity", 15, 30),
				(call_script,'script_object_modify_slot',obj_party,'$g_encountered_party',slot_town_player_relation,op_sub,':emnity'),
			(try_end),
			(jump_to_menu, "mnu_village_loot_no_resist"),
		(else_try),
			(eq, "$g_battle_result", -1),
			(jump_to_menu, "mnu_village_loot_defeat"),
		(try_end),
    ],
    [
      ("village_raid_attack",[],"Attack them.",[
          (store_random_in_range, ":emnity", 5, 10),
		  (call_script,'script_object_modify_slot',obj_party,'$g_current_town',slot_town_player_relation,op_sub,':emnity'),
          (call_script, "script_calculate_battle_advantage"),
          (set_battle_advantage, reg0),
          (set_party_battle_mode),
          (assign, "$g_battle_result", 0),
          (set_jump_mission,"mt_village_raid"),
          # (party_get_slot, ":scene_to_use", "$current_town", slot_castle_exterior),
          (jump_to_scene, "scn_village_battle"),
          (assign, "$g_next_menu", "mnu_village_start_attack"),
          (jump_to_menu, "mnu_battle_debrief"),
          (change_screen_mission),
          ]),
      ("village_raid_leave",[],"Leave this village alone...",[(change_screen_return)]),
    ],
  ),
  
  (
    "village_loot_no_resist",0,
    "The villagers quickly scatter before your forces. The village is at your mercy.",
    "none",
    [],
    [
      ("village_loot",[], "Loot the village and burn the houses.",
       [
          (call_script, "script_village_set_state", "$g_current_town", sts_being_raided),
		  (party_set_slot, "$g_current_town", slot_town_raided_by, "p_main_party"),
          (assign,"$g_player_raiding_village","$g_current_town"),
          (rest_for_hours, 3, 5, 1), #rest while attackable (3 hours will be extended by the trigger)
          (change_screen_return),
           ]),
      ("village_raid_leave",[],"Leave this village alone...",[(change_screen_return)]),
    ],
  ),
  (
    "village_loot_complete",0,
    "The village has been looted. You find {reg1} mon.",
    "none",
    [
        # (party_get_slot, ":village_lord", "$g_current_town", slot_town_lord),
        # (try_begin),
          # (gt,  ":village_lord", 0),
          # (call_script, "script_change_player_relation_with_troop", ":village_lord", -3),
        # (try_end),
        (store_random_in_range, ":emnity", 20, 40),
		(call_script,'script_object_modify_slot',obj_party,'$g_current_town',slot_town_player_relation,op_sub,':emnity'),
        (store_random_in_range, ":morale_increase", 10, 20),
        (call_script, "script_change_player_party_morale", ":morale_increase"),
        (store_random_in_range, ':percentage', 50, 80),
		(party_get_slot,':available_cash','$g_current_town',slot_town_treasury),
		(store_mul,':looted_cash',':available_cash',':percentage'),
		(val_div,':looted_cash',100),
		(call_script,'script_object_modify_slot',obj_party,'$g_current_town',slot_town_treasury,op_sub,':looted_cash'),
		(assign,reg1,':looted_cash'),
        (troop_add_gold, "trp_player", reg1),
      ],
    [
      ("continue",[], "Continue.",
       [
          (jump_to_menu, "mnu_close"),
          (troop_clear_inventory, "trp_temp_troop"),
          (reset_item_probabilities,100),
          (troop_add_merchandise,"trp_temp_troop",itp_type_goods,45),
          (change_screen_loot, "trp_temp_troop"),
        ]),
    ],
  ),
  (
    "village_loot_defeat",0,
    "Fighting with courage and determination, the villagers drive your forces away.",
    "none",
    [],
    [
      ("continue",[],"Continue...",[(change_screen_return)]),
    ],
  ),
  
  (
    "village_loot_continue",0,
    "Do you wish to continue looting this village?",
    "none",
    [],
    [
      ("continue",[],"Yes.",[ (rest_for_hours, 3, 5, 1), #rest while attackable (3 hours will be extended by the trigger)
                              (change_screen_return),
                              ]),
      ("continue",[],"No.",[(call_script, "script_village_set_state", "$g_current_town", 0),
                            (party_set_slot, "$g_current_town", slot_town_raided_by, -1),
                            (assign, "$g_player_raiding_village", 0),
                            (change_screen_return)]),
    ],
  ),
(
    "close",0,
    "Nothing.",
    "none",
    [
        (change_screen_return),
      ],
    [],
  ),
 (
      "temple",0,
      "{s1} {s2}.",
      "none",
      [
          (str_store_string,1,"str_enter_temple"),
          (str_store_party_name,2,"$g_encountered_party")
          ],
      [
          ("temple_enter",[],"Visit the temple.",[(party_get_slot,reg12,'$g_encountered_party',slot_town_kokujin),
                                                  (modify_visitors_at_site,'scn_temple'),
                                                  (reset_visitors),
                                                  (set_visitor,2,reg12),
                                                  (call_script,'script_modify_special_visitors','$g_encountered_party','scn_temple'),
                                                  (set_jump_mission,"mt_town_default"),
                                                  (set_jump_entry,1),
                                                  (jump_to_scene,'scn_temple'),
                                                  (change_screen_mission,0)]),
          ("temple_leave",[],"Leave.",[(rest_for_hours,1,4,0),(leave_encounter,0),(change_screen_return,0)]),
          ]
      ),
  (
      "bandit_camp",0,
      "You approach a bandit camp.",
      "none",
      [],
      [
          ("bandit_camp_enter",[],"Enter the hideout.",[(set_jump_mission,"mt_town_default"),
                                                        (jump_to_scene,"scn_bandit_hideout"),
                                                        (change_screen_mission,0)]),
          ("bandit_camp_leave",[],"Leave.",[(leave_encounter,0),(change_screen_return,0)]),
          ]
      ),
  (
      "army",0,
      "You approach a large and menacing army.",
      "none",
      [(store_encountered_party,reg1),
     (store_faction_of_party,reg2,reg1),
     (store_relation,reg3,reg2,"fac_player_faction")],
      [
          ("army_leave",[],"Run away.",[(leave_encounter,0),(change_screen_return,0)]),
          #("army_fight",[(store_encountered_party,reg1),
          #               (store_faction_of_party,reg2,reg1),
          #               (store_relation,reg3,reg2,"fac_player_faction"),
          #               (lt,reg3,0)],
          # "Attack.",[(val_sub,reg3,10),
          #            (set_relation,reg2,"fac_player_faction",reg3),
          #            (jump_to_menu,"mnu_army_encounter")]),
          ("army_talk", [(store_encountered_party,reg1),
                         (store_faction_of_party,reg2,reg1),
                         (store_relation,reg3,reg2,"fac_player_faction"),
                         (gt,reg3,0)],
           "Speak with the taisho.",[(leave_encounter,0),(change_screen_return,0)]),
          ]
      ),
  (
    "army_encounter",0,
    "You have engaged the army.",
    "none",
    [],
    [
      ("encounter_attack",[(store_troop_health,reg5),
                           (ge,reg5,5)],
                            "Charge the enemy",[(set_party_battle_mode),
                                                (set_jump_mission,"mt_lead_charge"),
                                                (jump_to_scene,"scn_random_scene"),
                                                (change_screen_mission,0)]),
      #("encounter_order_attack",[],"Order your troops to attack as you stay back.",[(simulate_battle,3)]), This needs work to fit into new encounter sys
      ("encounter_leave",[],"Leave.",[[leave_encounter],[change_screen_return]]),
    ]
  ),
(
	"intro_kuge_quest",0,
	"A menacing group of raiders has surrounded you.",
	"none",
	[(store_encountered_party,"$ikq_bandits")],
	[
		("ikq_fight",[],"Defend yourself.",
			[
				(set_party_battle_mode),
				(set_jump_mission,"mt_ikq_fight"),
				(call_script,'script_setup_random_scene'),
				(change_screen_mission,0),
				]
			),
		("ikq_talk",[],"Negotiate.",
			[
				(modify_visitors_at_site,"scn_conversation_scene"),
				(set_visitor,0,"trp_player"),
				(set_visitor,1,"trp_bandit_warlord"),
				(set_jump_mission,"mt_conversation_encounter"),
				(jump_to_scene,"scn_conversation_scene"),
				(change_screen_mission,0),
				]
			),
		("ikq_leave",
			[
				(this_or_next|eq,'$battle_won',1),
				(eq,"$ikq_negotiate",1),
				],
			"Leave.",
			[
				(try_begin),
					(party_is_active,"$ikq_bandits"),
					(remove_party,"$ikq_bandits"),
				(try_end),
				(leave_encounter,0),
				(change_screen_return,0),
				]
			),
		]
	),
  (
      "ikq_leave",0,
      "You have defeated the raiders.",
      "none",
      [],
      [
          ("ikq2_leave",[],"Leave.",
           [(store_encountered_party,reg0),
            (try_begin),
                (party_is_active,reg0),
                (disable_party,reg0),
            (try_end),
            (leave_encounter,0),
            (change_screen_return,0)]),
          ]
      ),
(
      'duelist',0,
      'You are approached by a duelist.',
      'none',
      [
          (try_begin),
              (eq,'$new_encounter',1),
              (assign,'$new_encounter',0),
              (assign,'$g_battle_result',0),
              (assign,'$battle_won',0),
          (else_try),
              (eq,'$battle_won',1),
              (assign,'$battle_won',0),
              (leave_encounter),
              (change_screen_return),
          (else_try),
              (lt,'$g_battle_result',0),
              (jump_to_menu,'mnu_defeated_by_duelist'),
          (try_end)],
      [
          ('duel_fight',[],'Accept the challenge,',[(set_party_battle_mode),
                                                    (party_stack_get_troop_id,':duelist','$g_encountered_party',0),
                                                    (modify_visitors_at_site,'scn_small_field'),
                                                    (reset_visitors),
                                                    (assign,reg1,1),
                                                    (assign,reg2,2),
                                                    (assign,reg3,3),
                                                    (assign,reg4,4),
                                                    (assign,reg5,5),
                                                    (assign,reg6,6),
                                                    (assign,reg7,7),
                                                    (assign,reg8,8),
                                                    (shuffle_range,1,5),
                                                    (shuffle_range,5,9),
                                                    (assign,':duelist_type',reg5),
                                                    (val_sub,':duelist_type',4),
													(assign,reg6,':duelist_type'),
													(assign,reg7,':duelist'),
													(display_message,'@Duelist debug: Troop ID: {reg7}; EP: {reg5}; Type: {reg6}',lt_blue_text),
                                                    (call_script,'script_modify_troop_stats',':duelist',':duelist_type'),
                                                    (set_visitor,reg5,':duelist'),
                                                    (set_jump_mission,'mt_duel'),
                                                    (set_jump_entry,reg1),
                                                    (jump_to_scene,'scn_small_field'),
                                                    (change_screen_mission)]),
          ('duel_leave',[],'Leave.',[(leave_encounter),(change_screen_return)]),
          ]
      ),
  (
      'defeated_by_duelist',0,
      'The duelist stands laughing over you as you lay there, barely alive. He robs you and wanders off in search of another fight.',
      'none',
      [
          (store_troop_gold,reg1,'trp_player'),
          (try_begin),
              (ge,reg1,100),
              (troop_remove_gold,'trp_player',100),
              (add_gold_to_party,'$g_encountered_party',100),
          (else_try),
              (lt,reg1,100),
              (assign,':index',0),
              (try_for_range,reg1,0,100),
                  (troop_set_slot,'trp_last_troop',reg1,-1), # initalize the array
              (try_end),
              (try_for_range,reg1,'itm_tanto','itm_end_items'),
                  (troop_has_item_equipped,'trp_player',reg1),
                  (troop_set_slot,'trp_last_troop',':index',reg1), # store any weapons carried by the player
                  (val_add,':index',1),
              (else_try),
                  (player_has_item,reg1),
                  (troop_set_slot,'trp_last_troop',':index',reg1), # store any weapons carried by the player
                  (val_add,':index',1),
              (try_end),
              (assign,reg61,':index'),
              (try_for_range,reg2,0,100), # store the length of the array
                  (troop_get_slot,':index','trp_last_troop',reg2),
                  (try_begin),
                      (neq,':index',-1),
                      (assign,':index_2',':index'),
                  (try_end),
              (try_end),
              (val_add,':index_2',1),
              (assign,':index',':index_2'),
              (assign,':item_1',0),
              (assign,':item_2',0),
              (assign,':item_val_1',0),
              (assign,':item_val_2',0),
              (try_for_range,reg3,0,':index'), #compares item values in player inventory
                  (troop_get_slot,':item_1','trp_last_troop',reg3),
                  (store_item_value,':item_val_1',':item_1'),
                  (gt,':item_val_1',':item_val_2'),
                  (assign,':item_val_2',':item_val_1'),
                  (assign,':item_2',':item_1'),
              (try_end),
              (troop_remove_item,'trp_player',':item_2'),
          (try_end)],
      [
          ('defeat_continue',[],'Continue...',
           [
              (store_random_in_range, reg(8), 18, 36),
              (rest_for_hours, reg(8),4,0),
              (assign,"$auto_menu","mnu_defeat_by_duelist_check"),
              (change_screen_return),
              ]),
          ]
      ),
  (
    "defeat_by_duelist_check",0,
    "stub",
    "none",
    [(jump_to_menu,"mnu_defeated_by_duelist_cont")],
    []
  ),
  (
      'defeated_by_duelist_cont',0,
      'You wake up some time later, bruised but alive. The only lasting damage is to your pride.',
      'none',
      [],
      [
          ('defeated_by_duelist_cont_cont',[],'Continue...',[(change_screen_return)]),
          ]
      ),
(
      'travelling_peddler',0,
      'You encounter a travelling peddler.',
      'none',
      [],
      [
          ('encounter_trade',[(neg|party_slot_eq,'$g_encountered_party',slot_spawn_intro,1)],
           'Trade with the merchants.',
           [(assign,'$new_encounter',0),
            (party_set_slot,'$g_encountered_party',slot_spawn_intro,1),
            (assign,reg51,'trp_merchant'),
            (modify_visitors_at_site,'scn_peddler'),
            (reset_visitors),
            (set_visitor,2,reg51),
            (set_jump_mission,'mt_town_default'),
            (set_jump_entry,1),
            (jump_to_scene,'scn_peddler'),
            (change_screen_mission)]),
          ("encounter_leave",[],"Leave.",[(leave_encounter),(change_screen_return)]),
          ]
      ),   
  (
      "null",mnf_auto_enter,
      "Nothing to see here. Move along.",
      "none",
      [],
      [
          ("null_leave",[],"Leave.",[(leave_encounter,0),(change_screen_return,0)]),
          ]
      ),
  (
      "custom_stuff",0,
      "What would you like made?",
      "none",
      [],
      [
          ("custom_armor",[],"A suit of armor.",[(jump_to_menu,"mnu_custom_armor")]),
          ("custom_helmet",[],"A kabuto.",[(jump_to_menu,"mnu_custom_helmet")]),
          ("custom_bow",[],"A yumi.",[(jump_to_menu,"mnu_custom_bow")]),
          ]
      ),
  (
      "custom_armor",0,
      "What would you like made?",
      "none",
      [],
      [
          ("custom_armor",[],"A haramaki dou.",[(jump_to_menu,"mnu_custom_haramaki")]),
          ("custom_helmet",[],"A maru dou.",[(jump_to_menu,"mnu_custom_marudou")]),
          ("custom_bow",[],"An o-yoroi.",[(jump_to_menu,"mnu_custom_oyoroi")]),
          ]
      ),
  (
      "custom_helmet",0,
      "Which helmet would you like?",
      "none",
      [],
      [
		("helmet_red",[],"A red helmet",[(assign,"$selection","itm_kasa_jikoro_kabuto_10")]),
		("helmet_green",[],"A green helmet",[(assign,"$selection","itm_kasa_jikoro_kabuto_3")]),
		("helmet_blue",[],"A blue helmet",[(assign,"$selection","itm_kasa_jikoro_kabuto_4")]),
		("helmet_purple",[],"A purple helmet",[(assign,"$selection","itm_kasa_jikoro_kabuto_7")]),
		("helmet_general",[],"A general's helmet",[(assign,"$selection","itm_kasa_jikoro_kabuto_2")]),
		]
      ),
  (
      "custom_bow",0,
      "Which bow would you like?",
      "none",
      [],
      [
		("bow_light_yumi",[],"A light yumi",[(assign,"$selection","itm_custom_light_yumi")]),
		("bow_yumi",[],"A yumi",[(assign,"$selection","itm_custom_yumi")]),
		("bow_heavy_yumi",[],"A heavy yumi",[(assign,"$selection","itm_custom_heavy_yumi")])
		]
      ),
  (
      "custom_haramaki",0,
      "Which haramaki would you like?",
      "none",
      [],
      [
		("haramaki_red",[],"A blue haramaki",[(assign,"$selection","itm_haramaki_dou_a")]),
		("haramaki_red",[],"A yellow haramaki",[(assign,"$selection","itm_haramaki_dou_b")]),
		("haramaki_red",[],"A red haramaki",[(assign,"$selection","itm_haramaki_dou_c")]),
		("haramaki_red",[],"A yellow haramaki with o-sode",[(assign,"$selection","itm_haramaki_douo")]),
		("haramaki_red",[],"A white haramaki with tsubo-sode",[(assign,"$selection","itm_haramaki_dout_a")]),
		("haramaki_red",[],"A red haramaki with tsubo-sode",[(assign,"$selection","itm_haramaki_dout_b")]),
		]
      ),
  (
      "custom_marudou",0,
      "Which marudou would you like?",
      "none",
      [],
      [
		("maru_red",[],"A blue marudou",[(assign,"$selection","itm_haramaki_dou_a")]),
		("maru_red",[],"A yellow marudou",[(assign,"$selection","itm_haramaki_dou_b")]),
		("maru_red",[],"A red marudou",[(assign,"$selection","itm_haramaki_dou_c")]),
		("maru_red",[],"A yellow marudou with o-sode",[(assign,"$selection","itm_haramaki_douo")]),
		("maru_red",[],"A white marudou with tsubo-sode",[(assign,"$selection","itm_haramaki_dout_a")]),
		("maru_red",[],"A red marudou with tsubo-sode",[(assign,"$selection","itm_haramaki_dout_b")]),
		]
      ),
  (
      "custom_oyoroi",0,
      "Which oyoroi would you like?",
      "none",
      [],
      []
      ),
  (
      "finish_purchase",0,
      "Thank you for your business.",
      "none",
      [],
      [
          ("finish_leave",[(troop_add_item,0,"$selection",0),
                           (store_item_value,reg2,"$selection"),
                           (val_mul,reg2,3),
                           (val_div,reg2,2),
                           (troop_remove_gold,0,reg2)],
           "Leave.",[(leave_encounter,0)]),
          ]
      ),
(
	'fort',0,
	'You enter a fort.',
	'none',
	[],
	[
	  ('fort_enter',[],'Speak with the fort commander.',
		[
		   (modify_visitors_at_site,'scn_manor'),
		   (reset_visitors),
		   (try_begin),
			   (party_slot_lt,'$g_encountered_party',slot_castle_progress,1000),
			   (party_set_slot,'$g_encountered_party',slot_castle_commander,'trp_geomancer'),
			   (set_visitor,3,'trp_geomancer'),
		   (else_try),
			   (assign,':commander',0),
			   (assign,':commander_level',0),
			   (party_get_num_companion_stacks,':num_stacks','$g_encountered_party'),
			   (try_for_range,':i',0,':num_stacks'),
				   (party_stack_get_troop_id,':troop_id','$g_encountered_party',':i'),
				   (store_character_level,':troop_level',':troop_id'),
				   (gt,':troop_level',':commander_level'),
				   (assign,':commander',':troop_id'),
			   (try_end),
			   (party_set_slot,'$g_encountered_party',slot_castle_commander,':commander'),
			   (set_visitor,3,':commander'),
		   (try_end),
		   (set_jump_mission,'mt_town_default'),
		   (set_jump_entry,1),
		   (jump_to_scene,'scn_manor'),
		   (change_screen_mission)]),
	  ('fort_leave',[],'Leave the fort.',[(leave_encounter),(change_screen_return)]),
	  ]
	),
##############################################################################################################
# Siege menus
##############################################################################################################

      
##############################################################################################################
# Infiltration menus
##############################################################################################################

('infiltration_start',0,'Infiltrate this installation','none',
	[
		
		],
	[
		('mission_start',[],'Organize the mission',
			[
				(party_clear,'p_main_party_backup'),
				(call_script,'script_party_copy','p_main_party_backup','p_main_party'),
				(party_clear,'p_main_party'),
				(jump_to_menu,'mnu_infiltration_organize'),
			]),
		('mission_abort',[],'Abandon the mission',
			[
				(leave_encounter),
				(change_screen_return),
			]),
		],
	),
('infiltration_organize',0,'Organize the mission. A successful infiltration is based on spotting and pathfinding abilites, of either the player alone, or an average of the entire infiltration team. A larger team has a greater chance of being spotted, but also has a higher suvivability rate.','none',
	[
		],
	[
		('mission_solo',[],'Attempt the mission solo',
			[
				(party_add_members,'p_main_party','trp_player',1),
				(party_remove_members,'p_main_party_backup','trp_player',1),
				(jump_to_menu,'mnu_infiltration_begin'),
				]),
		('mission_team',[],'Select a team for the mission',
			[
				(party_add_members,'p_main_party','trp_player',1),
				(party_remove_members,'p_main_party_backup','trp_player',1),
				(assign,'$g_infiltration_menu_first_time',1),
				(jump_to_menu,'mnu_infiltration_form_team'),
				]),
		],
	),
('infiltration_form_team',0,'{s5}','none',
	[
		#get verbage
		(try_begin),
			(eq,'$g_infiltration_menu_first_time',1),
			(assign,'$g_infiltration_menu_first_time',0),
			(str_store_string,5,'str_infiltration_menu_first_time'),
		(else_try),
			(str_store_string,5,'str_infiltration_menu_loop'),
		(try_end),
		#initialize the menu option list
		(try_for_range,reg1,0,5),
			(troop_set_slot,'trp_temp_troop',reg1,-1),
		(try_end),
		(assign,':mno_index',0),
		# determine if the team has capacity, and if the troop is already on the team, if a companion
		(party_get_num_companions,':temp_party_size','p_main_party'),
		(le,':temp_party_size',10),
		(party_get_num_companion_stacks,':num_stacks','p_main_party_backup'),
		(try_for_range,':i',0,':num_stacks'),
			(lt,':mno_index',5),
			(party_stack_get_troop_id,':troop','p_main_party',':i'),
			(try_begin),
				(troop_is_hero,':troop'),
				(party_get_num_companions,reg3,'p_main_party_backup',':troop'),
				(neq,reg3,0),
				(troop_set_slot,'trp_temp_troop',':mno_index',':troop'),
				(val_add,':mno_index',1),
			(else_try),
				(this_or_next|is_between,':troop',souhei_begin,souhei_end),
				(is_between,':troop',shinobi_begin,shinobi_end),
				(troop_set_slot,'trp_temp_troop',':mno_index',':troop'),
				(val_add,':mno_index',1),
			(try_end),
		(try_end),
		
		],
	[
		('team_add_stack_member_1',
			[
				(le,'$g_num_team_members',10),
				(troop_slot_neq,'trp_temp_troop',0,-1),
				(troop_get_slot,reg31,'trp_temp_troop',0),
				(str_store_troop_name,10,reg31),
				],
			'{s10}',
			[
				(try_begin),
					(troop_is_hero,reg31),
					(party_add_members,'p_main_party',reg35,1),
					(party_remove_members,'p_main_party_backup',reg35,1),
					(jump_to_menu,'mnu_infiltration_form_team'),
				(else_try),
					(assign,'$g_troop_to_add',reg31),
					(jump_to_menu,'mnu_infiltration_form_team_add_members'),
				(try_end),
				]),
		('team_add_stack_member_2',
			[
				(le,'$g_num_team_members',10),
				(troop_slot_neq,'trp_temp_troop',1,-1),
				(troop_get_slot,reg32,'trp_temp_troop',1),
				(str_store_troop_name,11,reg32),
				],
			'{s11}',
			[
				(try_begin),
					(troop_is_hero,reg32),
					(party_add_members,'p_main_party',reg35,1),
					(party_remove_members,'p_main_party_backup',reg35,1),
					(jump_to_menu,'mnu_infiltration_form_team'),
				(else_try),
					(assign,'$g_troop_to_add',reg32),
					(jump_to_menu,'mnu_infiltration_form_team_add_members'),
				(try_end),
				]),
		('team_add_stack_member_3',
			[
				(le,'$g_num_team_members',10),
				(troop_slot_neq,'trp_temp_troop',2,-1),
				(troop_get_slot,reg33,'trp_temp_troop',2),
				(str_store_troop_name,12,reg33),
				],
			'{s12}',
			[
				(try_begin),
					(troop_is_hero,reg33),
					(party_add_members,'p_main_party',reg35,1),
					(party_remove_members,'p_main_party_backup',reg35,1),
					(jump_to_menu,'mnu_infiltration_form_team'),
				(else_try),
					(assign,'$g_troop_to_add',reg33),
					(jump_to_menu,'mnu_infiltration_form_team_add_members'),
				(try_end),
				]),
		('team_add_stack_member_4',
			[
				(le,'$g_num_team_members',10),
				(troop_slot_neq,'trp_temp_troop',3,-1),
				(troop_get_slot,reg34,'trp_temp_troop',3),
				(str_store_troop_name,13,reg34),
				],
			'{s13}',
			[
				(try_begin),
					(troop_is_hero,reg34),
					(party_add_members,'p_main_party',reg35,1),
					(party_remove_members,'p_main_party_backup',reg35,1),
					(jump_to_menu,'mnu_infiltration_form_team'),
				(else_try),
					(assign,'$g_troop_to_add',reg34),
					(jump_to_menu,'mnu_infiltration_form_team_add_members'),
				(try_end),
				]),
		('team_add_stack_member_5',
			[
				(le,'$g_num_team_members',10),
				(troop_slot_neq,'trp_temp_troop',4,-1),
				(troop_get_slot,reg35,'trp_temp_troop',4),
				(str_store_troop_name,14,reg35),
				],
			'{s14}',
			[
				(try_begin),
					(troop_is_hero,reg35),
					(party_add_members,'p_main_party',reg35,1),
					(party_remove_members,'p_main_party_backup',reg35,1),
					(jump_to_menu,'mnu_infiltration_form_team'),
				(else_try),
					(assign,'$g_troop_to_add',reg35),
					(jump_to_menu,'mnu_infiltration_form_team_add_members'),
				(try_end),
				]),
		('team_add_stack_member_done',[],'Done',
			[
				(jump_to_menu,'mnu_infiltration_begin'),
				]),
		],
	),
('infiltration_form_team_add_members',0,'How many?','none',
	[
		(party_count_members_of_type,reg10,'p_main_party_backup','$g_troop_to_add'),
		],
	[
		('team_add_1',
			[
				(ge,reg10,1),
				(party_get_num_companions,reg11,'p_main_party'),
				(val_add,reg11,1),
				(le,reg11,10),
				],
			'1',
			[
				(party_add_members,'p_main_party','$g_troop_to_add',1),
				(party_remove_members,'p_main_party_backup','$g_troop_to_add',1),
				(jump_to_menu,'mnu_infiltration_form_team'),
				]),
		('team_add_3',
			[
				(ge,reg10,3),
				(party_get_num_companions,reg11,'p_main_party'),
				(val_add,reg11,3),
				(le,reg11,10),
				],
			'3',
			[
				(party_add_members,'p_main_party','$g_troop_to_add',3),
				(party_remove_members,'p_main_party_backup','$g_troop_to_add',3),
				(jump_to_menu,'mnu_infiltration_form_team'),
				]),
		('team_add_5',
			[
				(ge,reg10,5),
				(party_get_num_companions,reg11,'p_main_party'),
				(val_add,reg11,5),
				(le,reg11,10),
				],
			'5',
			[
				(party_add_members,'p_main_party','$g_troop_to_add',5),
				(party_remove_members,'p_main_party_backup','$g_troop_to_add',5),
				(jump_to_menu,'mnu_infiltration_form_team'),
				]),
		('team_add_all',
			[
				(party_count_members_of_type,reg12,'p_main_party_backup','$g_troop_to_add'),
				(party_get_num_companions,reg11,'p_main_party'),
				(val_add,reg11,reg12),
				(le,reg11,10),
				],
			'All',
			[
				(party_add_members,'p_main_party','$g_troop_to_add',reg12),
				(party_remove_members,'p_main_party_backup','$g_troop_to_add',reg12),
				
				]),
		('team_add_none',[],'None',
			[
				(jump_to_menu,'mnu_infiltration_form_team'),
				]),
		],
	),
('infiltration_begin',0,'You attempt to sneak inside...','none',
	[
		(party_get_num_companion_stacks,':num_stacks','p_main_party'),
		(assign,':total_pathfinding',0),
		(assign,':total_spotting',0),
		(try_for_range,':i',0,':num_stacks'),
			(party_stack_get_troop_id,':troop','p_main_party',':i'),
			(store_skill_level,reg1,':troop',skl_pathfinding),
			(val_add,':total_pathfinding',reg1),
			(store_skill_level,reg2,':troop',skl_spotting),
			(val_add,':total_spotting',reg2),
		(try_end),
		(store_add,':total_skill',':total_pathfinding',':total_spotting'),
		(party_get_num_companions,reg3,'p_main_party'),
		(val_div,':total_skill',reg3),
		(store_mul,':max_chance',reg3,2),
		(val_add,':max_chance',20),
		(store_random_in_range,':infiltration_chance',1,':max_chance'),
		(try_begin),
			(lt,':infiltration_chance',':total_skill'),
			(assign,'$g_infiltration_flag',1),
		(else_try),
			(assign,'$g_infilration_flag',2),
		(try_end),
		],
	[
		('infiltration_start_scene',[],'Continue...',
			[
				(set_jump_mission,'mt_infiltration'),
				(set_jump_entry,1),
				(jump_to_scene,'scn_infiltration_prescene'),
				(change_screen_mission),
				],
			),
		],
	),  


#####################################################################
## Captivity....
#####################################################################
#####################################################################
#####################################################################
#####################################################################

  (
    "captivity_start_wilderness",0,
    "Stub",
    "none",
    [
          (assign, "$g_player_is_captive", 1),
          (try_begin),
            (eq,"$g_player_surrenders",1),
            (jump_to_menu, "mnu_captivity_start_wilderness_surrender"), 
          (else_try),
            (jump_to_menu, "mnu_captivity_start_wilderness_defeat"), 
          (try_end),
      ],
    []
  ),
  
  (
    "captivity_start_wilderness_surrender",0,
    "Stub",
    "none",
    [
       (assign, "$g_player_is_captive", 1),
       (assign,"$auto_menu",-1), #We need this since we may come here by something other than auto_menu
       (assign, "$capturer_party", "$g_encountered_party"),
       (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
      ],
    []
  ),
  (
    "captivity_start_wilderness_defeat",0,
    "Your enemies take you as prisoner.",
    "none",
    [
       (assign, "$g_player_is_captive", 1),
       (assign,"$auto_menu",-1),
       (assign, "$capturer_party", "$g_encountered_party"),
       (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
    ],
    []
  ),
  (
    "captivity_start_castle_surrender",0,
    "Stub",
    "none",
    [
       (assign, "$g_player_is_captive", 1),
       (assign,"$auto_menu",-1),
       (assign, "$capturer_party", "$g_encountered_party"),
       (jump_to_menu, "mnu_captivity_castle_taken_prisoner"),
      ],
    []
  ),
  (
    "captivity_start_castle_defeat",0,
    "Stub",
    "none",
    [
       (assign, "$g_player_is_captive", 1),
       (assign,"$auto_menu",-1),
       (assign, "$capturer_party", "$g_encountered_party"),
       (jump_to_menu, "mnu_captivity_castle_taken_prisoner"),
      ],
    []
  ),
  (
    "captivity_start_under_siege_defeat",0,
    "Your enemies take you as prisoner.",
    "none",
    [
       (assign, "$g_player_is_captive", 1),
       (assign,"$auto_menu",-1),
       (assign, "$capturer_party", "$g_encountered_party"),
       (jump_to_menu, "mnu_captivity_castle_taken_prisoner"),
    ],
    []
  ),  
  (
    "captivity_wilderness_taken_prisoner",0,
    "Your enemies take you as prisoner.",
    "none",
    [
        #(set_background_mesh, "mesh_pic_prisoner_wilderness"),
     ],
    [
      ("continue",[],"Continue...",
       [
           (assign, "$g_player_is_captive", 1),
           (store_random_in_range, reg(8), 12, 19),
           (rest_for_hours, reg(8),4,0),
           (assign,"$auto_menu","mnu_captivity_wilderness_check"),
           (change_screen_return),
        ]),
    ]
  ),
  (
    "captivity_wilderness_check",0,
    "stub",
    "none",
    [(jump_to_menu,"mnu_captivity_end_wilderness_escape")],
    []
  ),
  (
    "captivity_end_wilderness_escape",0,
    "After painful days of being dragged about as a prisoner, you find a chance and escape from your captors!",
    "none",
    [
        #(set_background_mesh, "mesh_pic_escape_1"),
    ],
    [
      ("continue",[],"Continue...",
       [
           (assign, "$g_player_is_captive", 0),
           (party_set_slot,'p_main_party',slot_party_icon_state, pis_normal),
           (assign, "$capturer_party", "$g_encountered_party"),
           (party_relocate_near_party, "p_main_party", "$capturer_party", 2),
           (change_screen_return),
        ]),
    ]
  ),
  (
    "captivity_castle_taken_prisoner",0,
    "You are quickly surrounded by guards who take away your weapons. With curses and insults, they throw you into the dungeon where you will spend the miserable days of your captivity.",
    "none",
    [],
    [
      ("continue",[],"Continue...",
       [
           (assign, "$g_player_is_captive", 1),
           (store_random_in_range, reg(8), 16, 22),
           (rest_for_hours, reg(8),4,0),
           (assign,"$auto_menu", "mnu_captivity_castle_check"),
           (change_screen_return)
        ]),
    ]
  ),
##  (
##    "captivity_rescue_lord_taken_prisoner",0,
##    "Lord has escaped and you were taken prisoner.",
##    "none",
##    [],
##    [
##      ("continue",[],"Continue...",
##       [
##           (assign, "$g_player_is_captive", 1),
##           (store_random_in_range, reg(8), 16, 22),
##           (rest_for_hours, reg(8)),
##           (assign,"$auto_menu", "mnu_captivity_castle_check"),
##           (change_screen_return)
##        ]),
##    ]
##  ),
  (
    "captivity_castle_check",0,
    "stub",
    "none",
    [
        (store_random_in_range, reg(7), 0, 10),
        (try_begin),
          (lt, reg(7), 4),
          (store_random_in_range, "$player_ransom_amount", 3, 6),
          (val_mul, "$player_ransom_amount", 100),
          (store_troop_gold, reg3, "trp_player"),
          (gt, reg3, "$player_ransom_amount"),
          (jump_to_menu,"mnu_captivity_end_propose_ransom"),
        (else_try),
          (lt, reg(7), 7),
          (jump_to_menu,"mnu_captivity_end_exchanged_with_prisoner"),
        (else_try),
          (jump_to_menu,"mnu_captivity_castle_remain"),
        (try_end),
    ],
    []
  ),
  (
    "captivity_end_exchanged_with_prisoner",0,
    "After days of imprisonment, you are finally set free when your captors exchange you with a prisoner of their own.",
    "none",
    [],
    [
      ("continue",[],"Continue...",
       [
           (assign, "$g_player_is_captive", 0),
           (party_relocate_near_party, "p_main_party", "$capturer_party", 1),
           (change_screen_return),
        ]),
    ]
  ),
  (
    "captivity_end_propose_ransom",0,
    "After some time your captors come to you with an offer: In return for {reg5} mon of your hidden wealth, they propose to set you free. You decide to...",
    "none",
    [
        (store_character_level, ":player_level", "trp_player"),
        (store_mul, "$player_ransom_amount", ":player_level", 50),
        (val_add, "$player_ransom_amount", 100),
        (assign, reg5, "$player_ransom_amount"),
    ],
    [
      ("captivity_end_ransom_accept",[(store_troop_gold,":player_gold", "trp_player"),(ge, ":player_gold","$player_ransom_amount")],"Accept the offer.",
       [
           (assign, "$g_player_is_captive", 0),
           (troop_remove_gold, "trp_player", "$player_ransom_amount"), 
           (party_relocate_near_party, "p_main_party", "$capturer_party", 1),
           (rest_for_hours, 0),
           (change_screen_return),
        ]),
      ("captivity_end_ransom_deny",[],"Wait for a better chance.",
       [
           (assign, "$g_player_is_captive", 1),
           (store_random_in_range, reg(8), 16, 22),
           (rest_for_hours, reg(8),4,0),
           (assign,"$auto_menu", "mnu_captivity_castle_check"),
           (change_screen_return),
        ]),
    ]
  ),
  (
    "captivity_castle_remain",0,
    "Days pass in the darkness of your cell where you have to endure the hardships of captivity and the scorns of the guards...",
    "none",
    [
       # (set_background_mesh, "mesh_pic_prisoner_man"),        
        (store_random_in_range, reg(8), 16, 22),
        (rest_for_hours, reg(8),4,0),
        (assign,"$auto_menu", "mnu_captivity_castle_check"),
        
    ],
    [
      ("continue",[],"Continue...",
       [
           (assign, "$g_player_is_captive", 1),
           (change_screen_return),
        ]),
    ]
  ),
# Taxes
(
    "center_tax",0,
    "You receive the accumulated taxes of this fief amounting to {reg1} mon.",
    "none",
    [
        (str_clear, s3),
        (try_begin),
          (party_slot_eq, "$g_encountered_party", slot_town_lord, "trp_player"),
          (party_get_slot, ":accumulated_rents", "$g_encountered_party", slot_town_accumulated_rents),
          (party_get_slot, ":accumulated_tariffs", "$g_encountered_party", slot_town_accumulated_tariffs),
          (store_add, ":total_tax", ":accumulated_rents", ":accumulated_tariffs"),
          (assign, reg1, ":total_tax"),
          (troop_add_gold, "trp_player", ":total_tax"),
          (party_set_slot, "$g_encountered_party", slot_town_accumulated_rents, 0),
          (party_set_slot, "$g_encountered_party", slot_town_accumulated_tariffs, 0),
        (try_end),
      ],
    [
      ("continue",[], "Continue.",
       [
           (jump_to_menu,'$g_menu_caller'),
        ]),
    ],
  ),
(
	'test_prsnt',mnf_auto_enter,'You should not read this',
	'none',
	[
		(eq,'$g_exit_menu',false),
		(start_presentation,'prsnt_test_gui_objects'),
		(assign,'$g_exit_menu',true),
		],
	[
		('continue',[],'continue',
			[
				(assign,'$g_exit_menu',false),
				(change_screen_return,0),
				]),
		],
	),
 ]

debug = """
(
    "invite_player_to_faction",0,
    "You Receive an Offer of Vassalage^^{s8} of {s9} invites you to be his vassal and offers you the fief of {s2}.\
 In return he asks you to swear an oath of fealty to him and fight in his military campaigns.",
    "none",
    [
        #(set_background_mesh, "mesh_pic_messenger"),
        (faction_get_slot, "$g_invite_faction_lord", "$g_invite_faction", slot_faction_leader),
        (str_store_troop_name, s8, "$g_invite_faction_lord"),
        (str_store_faction_name, s9, "$g_invite_faction"),
        (str_store_party_name, s2, "$g_invite_offered_center"),
      ],
    [
      ("faction_accept",[],"Accept...",
       [(str_store_troop_name,s1,"$g_invite_faction_lord"),
        (setup_quest_text,"qst_join_faction"),

        (str_store_troop_name_link, s3, "$g_invite_faction_lord"),
        (str_store_faction_name_link, s4, "$g_invite_faction"),
        (str_store_party_name_link, s5, "$g_invite_offered_center"),
        (str_store_string, s2, "@Find and speak with {s3} of {s4} to give him your oath of fealty."),
        (call_script, "script_start_quest", "qst_join_faction", "$g_invite_faction_lord"),
        (call_script, "script_report_quest_troop_positions", "qst_join_faction", "$g_invite_faction_lord"),
        (jump_to_menu, "mnu_invite_player_to_faction_accepted"),
        ]),
      ("faction_reject",[],"Reject...",
       [(call_script, "script_change_player_relation_with_troop", "$g_invite_faction_lord", -3),
        (assign, "$g_invite_faction", 0),
        (assign, "$g_invite_faction_lord", 0),
        (assign, "$g_invite_offered_center", 0),
        (change_screen_return),
        ]),
     ]
  ),
  
  (
    "invite_player_to_faction_accepted",0,
    "{s3} will expect you to swear an oath of fealty to him. Therefore, you must find him and give him your oath. {s5}.",
    "none",
    [
        (call_script, "script_get_information_about_troops_position", "$g_invite_faction_lord", 0),
        (str_store_troop_name, s3, "$g_invite_faction_lord"),
        (str_store_string, s5, "@{s1}"),        
      ],
    [
      ("continue",[],"Continue...",
       [(change_screen_return),
        ]),
     ]
  ),
  
  """

